Error while reading image (.TIF)

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 Comments

That is not the file structure for TIF files!
Then could you tell me what is the correct struct?
Please
Tiff is a whole series of international standards.
https://www.loc.gov/preservation/digital/formats/fdd/fdd000022.shtml
Chances are that you should be using imread() instead, or at most the Tiff() class. You might need to reshape() to 3d afterwards, depending on how they represented the data.
Can you attach a link to a sample file on Google Drive or Dropbox?
U wanna send the struct to my google drive?
And I want to get a 1024 X 1024 matrix after reshaping raw_data.
Unfortunately the link your provided was the link each person uses to get to their own drive; you would need to post a link to the individual file so that other people can get to it.
Guess this is the one. Could you help me sending a struct file for reading tiff images to get 1024 X 1024 X 30, after reshaping, Xdim = 1024;Ydim = 1024 ; ZDim = 30; I get these dimensions if i read the image in (.spe) format but if i read them in tiff format get, Xdim = 109; YDim =160; Zdim = 165. I want 1024 for XDim, 1024 for YDim and 30 for ZDim.
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.
The link you sent appears to be to an empty Google Docs document.

Sign in to comment.

 Accepted Answer

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.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!