创建图像堆栈并编写GDF文件

时间:2014-07-24 19:04:11

标签: image matlab image-processing colors

我正在尝试编写一个函数,将一系列图像堆叠到图像堆栈中并将其转换为gdf文件。我对GDF文件了解不多,所以请帮帮我。

X=[];

for i=1:10

    if numel(num2str(i))==1
    X{i}=imread(strcat('0000',num2str(i),'.tif'));
    elseif numel(num2str(i))==2
    X{i}=imread(strcat('000',num2str(i),'.tif'));
    end
end

myImage=cat(3,X{1:10});
s=write_gdf('stack.gdf',myImage);

以上是读取标有00001至00010的图像,全部为灰度。一切都很好,除了在最后一行

s=write_gdf('stack.gdf',myImage);

当我运行它时,我收到一个错误:

Data type uint8 not supported

这意味着什么帮助?我应该将其转换为其他颜色格式吗? 提前谢谢!

1 个答案:

答案 0 :(得分:0)

我会写代码而不是这样(我没有write_gdf函数,所以我无法正确测试代码):

NumberOfFiles = 10;
X={};                 % preallocate CELL array
for n=1:NumberOfFiles % do not use "i" as your varable because it is imaginary unit in MatLab
    FileName = sprintf('%05d.tif',n);
    img      = imread(FileName); % load image
    X{i}     = double(img);      % and convert to desired format
end
myImage = cat(3,X{1:NumberOfFiles});
s = write_gdf('stack.gdf',myImage);

请记住

double(img);      % and convert to desired format

不会改变数据范围。即使是double格式的图像,如果磁盘上的格式为uint8,则其数据范围为0到255。如果您需要将数据标准化为0..1范围,则应该

X{i} = double(img)/255;

或以更多非正式形式

X{i} = double(img) / intmax(class(img));
相关问题