matlab - Convert a Matrix of doubles to a grayscale .tif image -


i have ncol nrow matrix of doubles want convert ncol nrow grayscale images of pixels. don't want cut down image scaled 256 channels. i'd happy using singles instead of doubles. i've looked through tiff class documentation mathworks can't find simple example this.

i tried read tiff class , yep poor documented. found going through trial , error:

lets have matrix

data = rand(100,200); 

lets save tiff:

t  = tiff('new.tif','w')                                   %create object of tiff class settag(t,tiff.tagid.imagelength,size(data,1))              %define image dimentions settag(t,tiff.tagid.imagewidth,size(data,2))  settag(t,'photometric', tiff.photometric.minisblack)       %define color type of image  %specifies how image data components stored on disk settag(t,'planarconfiguration',tiff.planarconfiguration.chunky);  settag(t,'bitspersample',64);                              %because 1 double = 8byte = 64bits  %specify how interpret each pixel sample (ieeefp works input doubles) settag(t,'sampleformat',tiff.sampleformat.ieeefp);          t.write(data) t.close 

lets test now:

datac = imread('new.tif') whos datac name         size              bytes  class     attributes datac      100x200            160000  double   

and:

datac(:,1)  ans =  0.4921 0.6908 0.1544 0.4433 ... 

Comments