我想知道imagesc和image在matlab中的区别
我用这个例子试图找出两者之间的区别,但我自己无法解释输出图像的区别;你能帮我吗?
I = rand(256,256);
for i=1:256
for j=1:256
I(i,j) = j;
end
end
figure('Name','Comparison between image et imagesc')
subplot(2,1,1);image(I);title('using image(I)');
subplot(2,1,2);imagesc(I);title('using imagesc(I)');
figure('Name','gray level of image');
image(I);colormap('gray');
figure('Name','gray level of imagesc');
imagesc(I);colormap('gray');
最佳答案
image
将输入数组显示为图像。当该输入是矩阵时,默认情况下 image
的 CDataMapping
属性设置为 'direct'
。这意味着输入的每个值都被直接解释为 颜色图中颜色的索引,超出范围的值将被剪掉:
image(C)
[...] WhenC
is a 2-dimensionalM
xN
matrix, the elements ofC
are used as indices into the currentcolormap
to determine the color. The value of the image object'sCDataMapping
property determines the method used to select a colormap entry. For'direct'
CDataMapping
(the default), values inC
are treated as colormap indices (1-based if double, 0-based if uint8 or uint16).
由于 Matlab 颜色图 默认情况下有 64 种颜色,在您的情况下,这会产生超过 64 种颜色的值被剪裁的效果。这就是您在 image
图表中看到的内容。
具体来说,在第一个图中,颜色图是默认的 parula
,有 64 种颜色;在第二张图中,colormap('gray')
应用了 64 个灰度级的灰色颜色图。例如,如果您在此图中尝试 colormap(gray(256))
,图像范围将匹配颜色的数量,并且您将获得与 imagesc
相同的结果.
imagesc
类似于 image
但应用自动缩放,以便图像范围跨越整个颜色图:
imagesc(...)
is the same asimage(...)
except the data is scaled to use the full colormap.
具体来说,imagesc
对应于 image
,CDataMapping
属性设置为 'scaled'
:
image(C)
[...] For'scaled'
CDataMapping
, values inC
are first scaled according to the axesCLim
and then the result is treated as a colormap index.
这就是为什么您在 imagesc
中看不到任何裁剪的原因。
关于image - matlab中image和imagesc有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33793034/