Error while reading image (.TIF)
Show older comments
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
Walter Roberson
on 11 Oct 2019
That is not the file structure for TIF files!
Ashwinraj Gnanavel
on 11 Oct 2019
Walter Roberson
on 11 Oct 2019
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.
Walter Roberson
on 11 Oct 2019
Can you attach a link to a sample file on Google Drive or Dropbox?
Ashwinraj Gnanavel
on 12 Oct 2019
Ashwinraj Gnanavel
on 12 Oct 2019
Walter Roberson
on 12 Oct 2019
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.
Ashwinraj Gnanavel
on 12 Oct 2019
Ashwinraj Gnanavel
on 12 Oct 2019
Walter Roberson
on 13 Oct 2019
The link you sent appears to be to an empty Google Docs document.
Accepted Answer
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!