阅读与阅读在Matlab中编写灰度TIF文件

时间:2016-06-24 06:47:07

标签: image matlab image-processing tiff

我正在尝试从大型灰度TIF文件中提取(非常)大量的子图像,并使用MATLAB将每个图像保存为GIF,PNG或其他TIF。我可以使用imshow(sub(:,:,1),cmap)显示单个图像,但是当我尝试将数据写入图像文件时,生成的文件只是白色方块101x101像素。使用cmap中的imwrite参数会产生相同的结果,就像更改图像格式一样(我尝试过使用PNG,TIF,GIF和JPG而没有运气)。根据Windows资源管理器中的属性菜单,文件a.tif为16位。任何帮助表示赞赏。我真的很想结束这个。


    % Import coordinates array and correct for multiplication by 10
    datafile = 'data.xlsx';
    coords = xlsread(datafile,1,'G2:H13057');
    x = coords(:,1) ./ 10;
    y = coords(:,2) ./ 10;
    r = 50;
    [img, cmap] = imread('a.tif'); % import the image

    s = 2*r+1; % scalar of size of each submatrix in the array (sise of image)
    sub = zeros(s,s,num); % create 3D matrix/array of matrices. Each submatrix corresponds to 50 px box around each point
    i = 1:4;
    subrgb = zeros(s,s,num);

    for i=1:4
       sub(:,:,i) = img((y(i)-r):(y(i)+r),(x(i)-r):(x(i)+r));
       filename = 'dot_%d.png';
       filename = sprintf(filename,i);
       imwrite(sub(:,:,i),filename,'png');
    end

1 个答案:

答案 0 :(得分:0)

尝试更改行:

sub = zeros(s,s,num); 

为:

sub = zeros(s,s,num,class(img));

我认为问题是sub是double类型。

祝你好运

相关问题