问题描述
我正在检查 pascal voc 2012的地面真相分割蒙版数据集.这些是单通道8位uint png文件.但是,当我在文件浏览器(nautilus)或图像查看器(eog)中打开这些图像时,它们将显示为彩色.
它不应该以灰度显示吗?
当我使用Matlab将图像存储为单通道8位uint png文件时,它会按预期以灰度显示. png文件类型不同有什么区别?
如何存储它,以便图像查看器以彩色显示它们?
I'm checking out the ground truth segmentation masks of the pascal voc 2012 dataset. These are single channel 8-bit uint png files. However when I open these images in either the file browser (nautilus) or the image viewer (eog) they are displayed in colors.
Shouldn't it be displayed in grayscale?
When I store an image as single channel 8-bit uint png file using Matlab, it is displayed in grayscale as expected. What is the difference are there different types of png files?
How can I store it such that my image viewer displays them in colors?
这是原始的单通道png:
This is the original single channel png:
这是imread
和imwrite
之后的结果.请注意,没有添加/删除任何频道:
This is the result after imread
and imwrite
. Note that NO channel has been added / removed:
推荐答案
您的图像文件包含索引图像,其中包含一个M×N索引矩阵和一个P×3色图矩阵.你怎么知道?加载您的文件时,您需要从 imread
中获取第二个输出图片:
Your image files contain indexed images, with an M-by-N index matrix and a P-by-3 colormap matrix. How can you tell? You need to get the second output from imread
when loading your images:
[img, cmap] = imread('zuIra.png');
if isempty(cmap)
% Process data as a grayscale or RGB image
else
% Process data as an indexed image
end
如果cmap
为空,则您的数据为M-by-N 灰度强度图像或M-by-N-by-3 真彩色RGB图像.否则,您将处理索引的彩色图像,并且必须在图像的任何处理中都使用这两个数据,例如使用 imshow
:
If cmap
is empty, your data is either an M-by-N grayscale intensity image or an M-by-N-by-3 Truecolor RGB image. Otherwise, you're dealing with an indexed color image, and will have to use both pieces of data in any processing of your image, such as viewing it with imshow
:
imshow(img, cmap);
或使用 imwrite
重新保存数据时:
Or when resaving the data with imwrite
:
imwrite(img, cmap, 'outfile.png');
如果您希望处理单个图像数据矩阵(在某些情况下可以简化处理),则可以使用 ind2rgb
:
If you would rather deal with a single image data matrix (which can make processing easier in some cases), you can convert the indexed image data and associated colormap into an RGB image with ind2rgb
:
imgRGB = ind2rgb(img, cmap);
这篇关于单通道png用颜色显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!