Error while reading image (.TIF)
2 views (last 30 days)
Show older comments
Ashwinraj Gnanavel
on 8 Oct 2019
Commented: Walter Roberson
on 13 Oct 2019
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
Accepted Answer
Harsha Priya Daggubati
on 11 Oct 2019
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 Comments
More Answers (0)
See Also
Categories
Find more on Call Python from MATLAB 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!