gpt4 book ai didi

image - matlab中image和imagesc有什么区别

转载 作者:太空宇宙 更新时间:2023-11-03 20:24:23 24 4
gpt4 key购买 nike

我想知道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 相同的结果.

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

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 中看不到任何裁剪的原因。

关于image - matlab中image和imagesc有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33793034/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com