Reading in a 32bit tif

11 visualizaciones (últimos 30 días)
Jon
Jon el 3 de Jul. de 2012
Hi there,
I am trying to read in a 32bit tif image that was taken with a x ray detector. The dynamic range on this detector is huge and it saves the pixels with intensities from 0 all the way up to 11,000,000 hence the 32 bits required. The image won't display with a normal image viewing software and will appear totally black as the vast majority of pixels have low values. But if you would like to see the picture I've uploaded it here http://www.2shared.com/photo/c_ElAUtM/fix.html
What I would like to do it read in the file to an array, do a little value changing and save it again as a 32 bit tif.
So far I've got this but I get a few errors when I run it from command prompt .
any help would be very much appreciated , thanks
imgdata = imread('fix.tif');
t = Tiff('myfile9.tif','w');
tagstruct.ImageLength = size(imgdata,1)
tagstruct.ImageWidth = size(imgdata,2)
tagstruct.Photometric = Tiff.Photometric.LinearRaw
tagstruct.BitsPerSample = 32
%tagstruct.SamplesPerPixel = 1
%tagstruct.RowsPerStrip = 16
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky
tagstruct.Software = 'MATLAB'
t.setTag(tagstruct)
t.write(imgdata);
t.close();
imagesc(imread('myfile9.tif'));

Respuesta aceptada

John
John el 3 de Jul. de 2012
The SampleFormat for your existing TIFF is signed integer. The tiff class is erroring out because you set the SampleFormat to UInt instead. Try settting it to Tiff.SampleFormat.Int instead.
  3 comentarios
John
John el 3 de Jul. de 2012
Yeah, I now see that you didn't actually set the tag, in which case LibTIFF defaults to UInt , which caused the problem. I would set SampleFormat around the same place you set BitsPerSample.
You are unfortunately about to run into a problem with the photometric interpretation, however. Writing signed integer is only currently supported with either MinIsBlack or MinIsWhite (grayscale) photometric interpretations. Any reason why you picked "LinearRaw"?
Jon
Jon el 4 de Jul. de 2012
Hi John
I had no reason for picking LinearRaw but I am now on MinIsBlack instead. Thanks for that suggestion.
Also the other suggestion that you made worked . I found I had to put the t.setTag('SampleFormat', Tiff.SampleFormat.Int); line of code just after the t.setTag(tagstruct).
You have been most helpful, lots of positive karma for you.
Thanks very much

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by