2015-04-07 11 views
4

我想要实现Photoshop中可用的渐变映射效果。 There's already a post that explains the desired outcome.此外,this answer占地面积正是我想做的事,但Python - 将彩色贴图应用于灰度numpy阵列并将其转换为图像

im = Image.fromarray(np.uint8(cm.gist_earth(myarray)*255)) 

工作不适合我,因为我不知道该怎么阵列正常化的1.0的值。

下面是我的代码,因为我打算它的工作。

im = Image.open(filename).convert('L') # Opening an Image as Grayscale 
im_arr = numpy.asarray(im)    # Converting the image to an Array 

# TODO - Grayscale Color Mapping Operation on im_arr 

im = Image.fromarray(im_arr) 

任何人都可以指出可能的选项和理想的方式来应用颜色映射到这个数组吗?我不想绘制它,因为似乎没有简单的方法将pyplot数字转换为图像。

另外,你能指出如何正常化数组,因为我无法这样做,并且无法在任何地方找到帮助。

回答

2

为了归您可以使用以下过程中的图像:

import numpy as np 
image = get_some_image() # your source data 
image = image.astype(np.float32) # convert to float 
image -= image.min() # ensure the minimal value is 0.0 
image /= image.max() # maximum value in image is now 1.0 

的想法是首先转移的形象,因此最小值是零。这也会照顾负面的最小值。然后用最大值对图像进行分割,所得到的最大值为1。

+1

谢谢!但对于这个问题,你是否也可以建议一种应用颜色图的方法? –

+0

您发布的代码不适用于我建议的添加规范化? – jnovacho

+0

它的确如此。我只想知道是否有办法在功能上应用自定义颜色映射。 –