python将图像转化为灰度图像_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图形转换为图像.

此外,你能指出如何规范化数组,因为我无法这样做,并且无法在任何地方找到帮助.

最佳答案 要标准化图像,您可以使用以下过程:

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值