Error while reading image (.TIF)

조회 수: 10 (최근 30일)
Ashwinraj Gnanavel
Ashwinraj Gnanavel 2019년 10월 8일
댓글: Walter Roberson 2019년 10월 13일
I have attached the segment of the main code (.mat) and the necessary function (get_TIF_raw_data2D) in .m format
The image is in .TIF format. When i ran the program with the image in .SPE format before ,i got the output. The output is it reads intensity of each pixel in the image.
Now, i want to run the program in .TIF format. But if i run in .TIF format ,i am getting an error stating that "Error using reshape
To RESHAPE the number of elements must not change".
Do I need to make any changes while running in the function while running in .TIF format. Can anyone help me out to debug the function so that I could get the ouput while running in .TIF format also?
Do I need to change the number of bits in the function code? Please help me out.
Maincode:
Ci_temp = 'c_init_notip.TIF';
Ci = get_TIF_raw_data2D(Ci_temp);
clear Ci_temp;
Ci_d = double(Ci);
clear Ci;
Ci_avg = mean(Ci_d, 3);
Function:
function [extracted_data header] = get_TIF_raw_data2D(filename)
fid=fopen(filename);
headersize=4100;
raw_data=[];
header = fread(fid,2050,'uint16=>uint16'); % 2050 uint16 = 4100 bytes = 32800 bits
Xdim = header(22); %raw_data_width %width as pixel number for each frame
Ydim = header(329); %raw_data_height % height as pixel number for each frame
Zdim = header(724); %
DataType = header(55);
if Zdim == 0
Zdim =1;
end
%Total_Size_XYZ = Xdim*Ydim*Zdim
%raw_data
switch DataType
case 0 % FLOATING POINT (4 bytes / 32 bits)
raw_data = fread(fid,inf,'float32=>float32');
case 1 % LONG INTEGER (4 bytes / 32 bits)
raw_data = fread(fid,inf,'int32=>int32');
case 2 % INTEGER (2 bytes / 16 bits)
raw_data = fread(fid,inf,'int16=>int16');
case 3 % UNSIGNED INTEGER (2 bytes / 16 bits)
raw_data = fread(fid,inf,'uint16=>uint16');
end
fclose(fid);
frame4view1 = reshape(raw_data,Xdim,Ydim,Zdim);
clear raw_data; %clear some memory
%permute the X and Y dimensions so that an image looks like in Winview
frame4view1 = permute(frame4view1,[2,1,3]);
extracted_data = frame4view1;
  댓글 수: 10
Ashwinraj Gnanavel
Ashwinraj Gnanavel 2019년 10월 12일
I could not send the tiff file image here as its more than 5 MB , i could send the image to you in the email through a google drive. So kindly please send me your email ID, I am stuck with this problem for the past one week.
Walter Roberson
Walter Roberson 2019년 10월 13일
The link you sent appears to be to an empty Google Docs document.

댓글을 달려면 로그인하십시오.

채택된 답변

Harsha Priya Daggubati
Harsha Priya Daggubati 2019년 10월 11일
Hi,
These are links to the questions answered by the community, which kind of relates to your issue.
Hope this helps! If the problem is not solved, I suggest attaching your tif file if possible.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by