问题描述
我使用了 8 位灰度 256x256 lena 图片(图 3)。
figure; imshow(imread('lena.png'))
figure; imshow(data)
figure; imshow('lena.png')
我的代码有什么问题?
解决方法
从对 imshow
的三种不同调用中,正确的一种似乎是您将文件路径传递给它的那种。阅读 imshow
的源代码,您会看到它还读取图像颜色图。
似乎您没有简单的灰度图像,而是有索引图像,因此您应该这样做:
[img,cmap] = imread (...);
imshow (img,cmap);
顺便说一下,在我看来,您正在尝试预先分配图像数据。如果是这样,你就做错了。
# The pre-allocation with zeros here does nothing. Not only does
# imread creates its own new array,its data type will be uint8 while
# zeros is creating one of doubles by default.
data = zeros(256,256) ;
data = imread('lena.png');