Azzera filtri
Azzera filtri

Reading in a 32bit tif

15 visualizzazioni (ultimi 30 giorni)
Jon
Jon il 3 Lug 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'));

Risposta accettata

John
John il 3 Lug 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 Commenti
John
John il 3 Lug 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 il 4 Lug 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

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by