Tiff import into a matrix becomes integer only

3 Ansichten (letzte 30 Tage)
Joe Sheppard
Joe Sheppard am 11 Dez. 2019
Hello all,
I've modified some code I found online which can quickly import tiff files into matrices in MatLab. Speed is important for me because I have 20 stacks of 1200x1200x250.
The code imports the tiffs just fine, but it is changing the actual pixel values of the data.
Before import the tifs are 8-bit (0-255) but all pixels values lay between 0-5 (with decimal places).
When I important into matlab all the pixel values become whole integers which means I lose all the data since my range is so small.
I have tried changing the data type from uint8, uint16, single and double but this does not solve the issue. I have attached my code below:
files = dir ('*.tif'); % identify all tif files in the current directory
for j=1:size(files,1) % this loop extracts info about the tifs, and saves it to a structure array called "files"
FileTif= files(j).name;
InfoImage=imfinfo(FileTif);
mImage = InfoImage(1).Width;
nImage = InfoImage(1).Height;
NumberImages = length(InfoImage);
FinalImage=zeros(nImage,mImage,NumberImages,'single');
TifLink = Tiff(FileTif, 'r'); % it also makes a tiff library which I don't understand - but the internet said this would load them into matlab faster
for i=1:NumberImages
TifLink.setDirectory(i);
FinalImage(:,:,i)=TifLink.read();% each tiff is read into matlab as an individual 3D matrix - just like a tiff stack
end
FinalImage = single(FinalImage);
TifLink.close();
files(j).data = FinalImage; % the matrix is then written into the "files" structure array
end

Antworten (0)

Kategorien

Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by