Tiff import into a matrix becomes integer only
조회 수: 3 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!