matlab中image和imagesc有什么区别

what is the difference between image vs imagesc in matlab

我想知道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 将输入数组显示为图像。当该输入是矩阵时,默认情况下 imageCDataMapping 属性 设置为 'direct'。这意味着输入的每个值都被直接解释为颜色映射中颜色的索引,并且超出范围的值被剪裁:

image(C) [...] When C is a 2-dimensional MxN matrix, the elements of C are used as indices into the current colormap to determine the color. The value of the image object's CDataMapping property determines the method used to select a colormap entry. For 'direct' CDataMapping (the default), values in C 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.

相同的结果

imagescimage 类似,但应用 自动缩放 ,以便图像范围跨越整个颜色图:

imagesc(...) is the same as image(...) except the data is scaled to use the full colormap.

具体来说,imagesc 对应于 imageCDataMapping 属性 设置为 'scaled':

image(C) [...] For 'scaled' CDataMapping, values in C are first scaled according to the axes CLim and then the result is treated as a colormap index.

这就是为什么您没有看到 imagesc 的任何剪辑。