Matlab。无法将双数组合并为 RGB 图像
Matlab. Can't merge double arrays into RGB image
我在 Matlab (m,n,3)[double] 中有一个彩色 rgb 图像。我分别在每个通道上执行线性扩散过程。 LinearDiffusion 输出中的第一个元素是双精度数组 (m,n,1)。
[m,n,j]=size(noisy_image)
rgb_im=zeros(m,n,3);
for chn=1:3
noisy_chn=noisy_image(:,:,chn);
[rgb_im(:,:,chn), diff_un]=LinearDiffusion2016(noisy_chn, 0, dt, maxnl);
end
我想显示 rgb_im,即 (m,n,3)[double]。但无论我做什么,总是得到一个空白方块,即使图像值没有饱和。我对灰度(uint8)图像没有任何问题。有什么想法吗?
更新: 源图像是 (m,n,3)[unit8],但我将每个通道变成双通道以将其馈送到 LinearDiffusion。
谢谢。
前提是rgb图像的每个通道都必须是uint8(不是double!!)。这条线成功了:
imshow(uint8(rgb_im));
此致
原因是 MATLAB 将图像中的浮点数解释为 0 到 1(含)之间的分数,而整数被解释为 0 到 255(含)之间的位值。您已将整数值转换为双精度值,对它们进行数学计算,然后直接将它们传送回 imshow
。 MATLAB 发现它们是双精度值,并将所有大于 1 的值限制在 1,因此您看到的都是白色,除非您碰巧有一些纯黑色像素。您有两个选择:像您在自我回答中所做的那样转换回整数,或者除以 255 以重新调整值。
如果在 imshow
帮助文件中提供此信息会很有帮助,但您必须深入研究低级 CData 图像 属性 才能获取此信息:
Image color data, specified in one of these forms:
3-D array of RGB triplets — This format defines true color image data using RGB triplet values. Each RGB triplet defines a color for one pixel of the image. An RGB triplet is a three-element vector that specifies the intensities of the red, green, and blue components of the color. The first page of the 3-D array contains the red components, the second page contains the green components, and the third page contains the blue components. Since the image uses true colors instead of colormap colors, the CDataMapping property has no effect.
If CData is of type double, then an RGB triplet value of [0 0 0] corresponds to black and [1 1 1] corresponds to white.
If CData is an integer type, then the image uses the full range of data to determine the color. For example, if CData is of type uint8, then [0 0 0] corresponds to black and [255 255 255] corresponds to white. If CData is of type int8, then [-128 -128 -128] corresponds to black and [127 127 127] corresponds to white.
If CData is of type logical, then [0 0 0] corresponds to black and [1 1 1] corresponds to white.
我在 Matlab (m,n,3)[double] 中有一个彩色 rgb 图像。我分别在每个通道上执行线性扩散过程。 LinearDiffusion 输出中的第一个元素是双精度数组 (m,n,1)。
[m,n,j]=size(noisy_image)
rgb_im=zeros(m,n,3);
for chn=1:3
noisy_chn=noisy_image(:,:,chn);
[rgb_im(:,:,chn), diff_un]=LinearDiffusion2016(noisy_chn, 0, dt, maxnl);
end
我想显示 rgb_im,即 (m,n,3)[double]。但无论我做什么,总是得到一个空白方块,即使图像值没有饱和。我对灰度(uint8)图像没有任何问题。有什么想法吗?
更新: 源图像是 (m,n,3)[unit8],但我将每个通道变成双通道以将其馈送到 LinearDiffusion。
谢谢。
前提是rgb图像的每个通道都必须是uint8(不是double!!)。这条线成功了:
imshow(uint8(rgb_im));
此致
原因是 MATLAB 将图像中的浮点数解释为 0 到 1(含)之间的分数,而整数被解释为 0 到 255(含)之间的位值。您已将整数值转换为双精度值,对它们进行数学计算,然后直接将它们传送回 imshow
。 MATLAB 发现它们是双精度值,并将所有大于 1 的值限制在 1,因此您看到的都是白色,除非您碰巧有一些纯黑色像素。您有两个选择:像您在自我回答中所做的那样转换回整数,或者除以 255 以重新调整值。
如果在 imshow
帮助文件中提供此信息会很有帮助,但您必须深入研究低级 CData 图像 属性 才能获取此信息:
Image color data, specified in one of these forms:
3-D array of RGB triplets — This format defines true color image data using RGB triplet values. Each RGB triplet defines a color for one pixel of the image. An RGB triplet is a three-element vector that specifies the intensities of the red, green, and blue components of the color. The first page of the 3-D array contains the red components, the second page contains the green components, and the third page contains the blue components. Since the image uses true colors instead of colormap colors, the CDataMapping property has no effect.
If CData is of type double, then an RGB triplet value of [0 0 0] corresponds to black and [1 1 1] corresponds to white.
If CData is an integer type, then the image uses the full range of data to determine the color. For example, if CData is of type uint8, then [0 0 0] corresponds to black and [255 255 255] corresponds to white. If CData is of type int8, then [-128 -128 -128] corresponds to black and [127 127 127] corresponds to white.
If CData is of type logical, then [0 0 0] corresponds to black and [1 1 1] corresponds to white.