Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply gradient map on a grey scale image

I've searched for any possible solution for that, but all the answers are not really clear or incomplete.

So, say I have the image uploaded into memory:

image = Image.open('image.jpg')

How do I apply this gradient (#582f91 to #00aeef):

enter image description here

To this image:

enter image description here

So it becomes this:

enter image description here

Thanks ahead.

like image 617
Andrey Shipilov Avatar asked Dec 08 '25 08:12

Andrey Shipilov


1 Answers

Just use LinearSegmentedColormap :

# make a cmap
mycm=matplotlib.colors.LinearSegmentedColormap.from_list('',['#582f91', '#00aeef'])

# apply on a canal
imgrad=mycm(image[:,:,0])
like image 143
B. M. Avatar answered Dec 11 '25 05:12

B. M.