Octave之TIFF格式图像存储格式猜测

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_24894159/article/details/53242879

今天在处理TIF(tiff)格式的图像时,发现这样显示的图像是一片黑:

I = imread("forest.tif");
imshow(I);
并提示了这样的警告:

warning: your version of GraphicsMagick limits images to 16 bits per pixel
warning: called from
    imformats>default_formats at line 256 column 11
    imformats at line 79 column 3
    imageIO at line 92 column 11
    imread at line 106 column 30
    ex1_tif at line 2 column 8
大概翻译一下:你当前版本的图像处理工具限制每个像素为16bit。

惯性思维,反正是警告,没怎么理会,反正能显示:

诶?这是什么鬼?怎么全是黑色的?黑色森林?(csdn水印请忽略)

后来查看知道是这样显示的:

%读入森林图片
[I2,M2] = imread("forest.tif");
imshow(I2,M2);
这样就正确了


为什么这样才可以呢?JPG的图片那样也可以啊?

我们输出了图像信息

info = imfinfo("forest.tif");
disp(info);
scalar structure containing the fields:

    Filename =  ...\octave-4.0.3\workspace\image_ex1\forest.tif
    FileModDate =  4-Dec-2000 13:57:58
    FileSize =  124888
    Format = TIFF
    FormatVersion =
    Width =  447
    Height =  301
    BitDepth =  16
    ColorType = indexed
    DelayTime = 0
    DisposalMethod =
    LoopCount = 0
    ByteOrder = undefined
    Gamma = 0
    Chromaticities = [](1x0)
    Comment = Carmanah Ancient Forest, British Columbia, Canada
    Quality =  75
    Compression = undefined
    Colormap =

       1.00000   1.00000   1.00000
       0.00000   1.00000   1.00000
....
中间有两个信息很有用:colorType = indexed  bitDepth = 16

分别是:颜色类型为索引类型,位深为16位。

imreade格式为 [X,Map] = imread(filename,format);

这个Map是什么东西?

查看workspace


可以看到M2为256*3的矩阵,double类型。经搜索3列标识rgb值。256,?

嗯似乎和16有着什么关系?

又想着之前的警告,每个像素限制到16位,这里的位深也是16位,16*16=256不好解释啊,

索引位图?

I2中每个值都小于256?

似乎猜到了什么?

所以猜测:由于限制到每个位为16bit,可能是I2存储颜色的索引值,Map表示着256种颜色

I2中存的为Map中的行数,(不过0对应map中的第一行)

测试:

把颜色1:置为黑色,

%把I2中前20行索引置为0,第一行
I2([1:1:20],:)=0;
%颜色1置为黑色
M2(1,:) = 0;
显示


果然如此。




猜你喜欢

转载自blog.csdn.net/qq_24894159/article/details/53242879