【发布时间】:2016-10-01 15:47:51
【问题描述】:
我和他有同样的问题:Scaling a matrix in OpenCV
我和他有同样的问题,我有一张彩色图片,我用matlab读取图片:Input = imread('input1.jpg');,图片格式为612x612x3 uint8,我打印图片中的5x5x1像素如下: Input(1:5,1:5,1)
201 201 201 201 201
201 201 201 201 201
202 202 202 202 202
203 203 203 203 203
204 204 204 204 204
通过使用mat2gray函数:rgb_out = mat2gray(Input);,这些像素可以转换成这个,它们都在0到1之间:rgb_out(1:5,1:5,1)
0.9684 0.9455 0.9266 0.9099 0.9047
0.9657 0.9542 0.9432 0.9354 0.9299
0.9642 0.9571 0.9502 0.9495 0.9456
0.9621 0.9609 0.9562 0.9532 0.9516
0.9673 0.9633 0.9597 0.9580 0.9575
所以问题是如何在 Opencv 中使用 Python 实现这一点,我尝试了如下代码:
print(Input)
rgb_out = np.zeros(Input.shape, np.uint8)
cv2.normalize(Input,rgb_out,1,0,cv2.NORM_MINMAX)
print(rgb_out)
但第一个打印是:
[[[205 207 201]
[205 207 201]
[205 207 201]
...,
[232 254 242]
[232 254 242]
[231 253 241]]...
并且rgb_out中的元素不超过1或0。请帮忙,谢谢。
【问题讨论】: