malab把single数据保存为tif

function t = saveAsTiffSingle(X, filepath)
% https://www.cnblogs.com/lionyiss/p/9552979.html
    im = single(X);
    t = Tiff(filepath,'w');
    tagstruct.ImageLength = size(im,1);
    tagstruct.ImageWidth = size(im,2);  

    tagstruct.Photometric = 1;

    % 每个像素的数值位数,single为单精度浮点型,对于32为系统为32
    tagstruct.BitsPerSample = 32;

    tagstruct.SamplesPerPixel = 1;
%     tagstruct.RowsPerStrip = 16;
    tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;

    tagstruct.Software = 'MATLAB';

    tagstruct.SampleFormat = 3;
    t.setTag(tagstruct)

    t.write(im);

    t.close
end

posted @ 2024-07-26 19:38  祥瑞哈哈哈  阅读(5)  评论(0编辑  收藏  举报