Saving indexed tif images from for loop: Problem with file size.
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi, I have the following loop that takes a 32-bit 4D data set data(m,n,i,j) and outputs i*j indexed m by n images.
fid=fopen('myfile','rb','ieee-le');
data4D=fread(fid,'int32');
image_dir=pwd;
for i=1:size(data4D,3)
for k=1:size(data4D,4)
data3D=squeeze(abs(data4D(:,:,1:1:end,k)));
data2D=(mat2gray(squeeze(data3D(:,:,i))));
baseFileName = strcat( 'Image_', num2str(k) ...
, 'SubImage_', num2str(i),'.tif');
fullFileName = fullfile(image_dir,baseFileName);
imwrite(data2D, fullFileName);
end
end
This saves the images, but they are not the correct file size, or bit number. I have tried to use the Tiff function to save the images, but I must not be doing it incorrectly, because the images are saved, but they all look 100% black. Is there a Matlab master out there who can tune up this script?
Thanks?
댓글 수: 0
답변 (1개)
Image Analyst
2014년 11월 21일
I don't think TIFF can take pixels in the range 0-1. Well maybe it can with special options. But you're calling mat2gray so why not simply multiply it by 255 and cast to uint8?
data2D= uint8(255*mat2gray(squeeze(data3D(:,:,i))));
댓글 수: 9
Image Analyst
2014년 11월 25일
Please answer my question about the original range of the data. It may well be that the upper bytes are not being used.
You say your code "takes a 32-bit 4D data set data(m,n,i,j)". What is the data type of "data"? Is it int32, uint32, or single? It's not double like you said above if it's only 32 bits. Double is 8 bytes or 64 bits.
참고 항목
카테고리
Help Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!