简体   繁体   English

显示图像

[英]Showing an image

I came to a matlab code where it first reads an image and converts it to double as follows: 我来到了一个matlab代码,它首先读取图像并将其转换为double ,如下所示:

I = double(imread(img));

After that, it shows the image as follows: 之后,它显示图像如下:

imshow(I/max(I(:)))

What does that mean? 这意味着什么? Especially when I removed the max part, I got only an image with a white background. 尤其是当我移除max部分时,我只会得到带有白色背景的图像。 What is the goal of such division? 这种划分的目标是什么? And, why does it show the image properly when done and doesn't show the image properly if you directly show the read image without the division by max? 而且,为什么在完成后为什么正确显示图像,而直接显示读取的图像而不进行除以最大值,为什么它不能正确显示图像呢?

Thanks. 谢谢。

The expression: 表达方式:

I/max(I(:))

just normalises the pixel values to the range 0..1.0. 只是将像素值标准化为0..1.0范围。 It does this by dividing all pixel values by the max value. 它通过将所有像素值除以最大值来实现。

max(I(:)) seems to be a normalize step max(I(:))似乎是标准化步骤

From the documentation follows that imshow needs a input matrix having values between 0 and 1.0 文档中可以看出,imshow需要一个值在0到1.0之间的输入矩阵

imshow(I) displays the image I in a Handle Graphics® figure, where I is a grayscale, RGB (truecolor), or binary image. imshow(I)以HandleGraphics®图形显示图像I,其中I是灰度,RGB(真彩色)或二进制图像。 For binary images, imshow displays pixels with the value 0 (zero) as black and 1 as white. 对于二进制图像,imshow将值为0(零)的像素显示为黑色,将值为1的像素显示为白色。

I is a 2D or 3D matrix (depends on grayscale or color). I是2D或3D矩阵(取决于灰度或颜色)。 I(:) is the vector where all values of the matrix are written in a column, just like they are arranged in the memory; I(:)是向量,矩阵的所有值都排列在列中,就像它们在内存中排列一样; you could do by reshape as well. 您也可以通过reshape来完成。 Please read more about the colon-operator in Matlab documentation , it is an absolut basic concept of Matlab. 请在Matlab文档中阅读有关冒号运算符的更多信息,这是Matlab的绝对基本概念。

max gives you the maximum over a vector, ie max(I(:)) gives you the maximum value over the whole image. max为您提供矢量的最大值,即max(I(:))为您提供整个图像的最大值。

It is an unwritten law that the range of an image starts at 0. Therefore you can map the values of the image to [0,1] by dividing it by max(I(:)) . 图像的范围从0开始是不成文的定律。因此,可以通过将图像的值除以max(I(:))来将图像的值映射到[0,1] In Matlab it is done like that: myMatrix/myScalar . 在Matlab中,是这样完成的: myMatrix/myScalar

So I/max(I(:)) gives you the image with values in [0,1] , what is required for double-images that you want to show with imshow . 因此, I/max(I(:))为您提供的图像的值为[0,1] ,这是要使用imshow显示的双图像所需的imshow

Please note: 请注意:

(1) You can write imshow(I,[]) instead which will show you the image with values stretched to [0,1] (in difference to your version the minimum is mapped to 0 as well). (1)您可以编写imshow(I,[])来代替,它将向您显示图像的值拉伸到[0,1] (与您的版本不同,最小值也映射为0)。

(2) In my view you should map the values of an image for visualization only in exceptional cases like you do. (2)在我看来,您应该仅在像您这样的例外情况下映射图像的值以进行可视化。 It can give you wrong impression of the image (eg a very dark image will be visualized as full contrast image). 它可能给您留下错误的图像印象(例如,非常暗的图像将被可视化为全对比度图像)。 Try to devide by maximum of the original value range (often 255, 4095 or 65535). 尝试指定原始值范围的最大值(通常为255、4095或65535)。 Example: 例:

img = imread('some12bit.png');
img = double(img);
img = img / 4095; % [0,4095] -> [0,1]
imshow(img);

(3) Without mapping the image to [0,1] all values > 1 will be interpreted as 1 . (3)如果不将图像映射到[0,1]所有> 1值都将解释为1 That's why your image is shown as a white image without mapping it to [0,1] before. 这就是为什么您的图像显示为白色图像而不将其映射到[0,1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM