imread error obtaining file type

1 view (last 30 days)
Rachel Ball
Rachel Ball on 15 Mar 2023
Answered: Ryan Baird on 15 Mar 2023
I am writing code to read 2 images in and compare their pixels individually to create a confusion matrix. My code is as followed
%import the 2 files (hand segmented and NN segmented)
hand_seg = dir(['Z:\eee_biophotonics1\Shared\SPOT dataset (Training dat' ...
'a)\Testing Images\images 123 network 456 (completed)\hand seg\*.tif']);
NN_seg = dir(['Z:\eee_biophotonics1\Shared\SPOT dataset (Training data' ...
')\Testing Images\images 123 network 456 (completed)\nn seg\*.tif']);
%set parameters
colour_hand = nan; %black is not epidermis, grey is
colour_NN = nan; %black is not epidermis, grey is
x = nan; y = nan; %dimensions of images and number of image in file
x_max = 400; y_max = 512; %sizes of images
FP = 0; FN = 0; TP = 0; TN = 0; %for confusion matrix
acc = nan; spec = nan; sens = nan;
nfiles = length(hand_seg);
%loop for image scanning
for j = 1 : nfiles
%opens hand seg images
image_hand = hand_seg(j).name;
folder_hand = hand_seg(j).folder;
full_dir_hand = fullfile(folder_hand,image_hand);
im_hand = imread(full_dir_hand);
%opens hand seg images
image_NN = NN_seg(j).name;
folder_NN = NN_seg(j).folder;
full_dir_NN = fullfile(folder_NN,image_NN);
im_NN = imread(full_dir_NN);
for x = 1:x_max
for y = 1:y_max
colour_hand = impixel(im_hand,x,y); %gets colour value of pixel
% of gold standard
colour_NN = impixel(im_NN,x,y); %gets colour value of pixel of
% NN
%adds values to the confusion matrix
if colour_hand == 0 && colour_NN == 0 %not epidermis for gold
%standard, not epidermis for NN (true negative)
TN = TN + 1;
elseif colour_hand == 0 && colour_NN ~= 0 %not epidermis for
%gold standard, epidermis for NN (false positive)
FP = FP + 1;
elseif colour_hand ~= 0 && colour_NN == 0 %epidermis for the
%gold standard, not epidermis for the NN (false negative)
FN = FN + 1;
elseif colour_hand ~= 0 && colour_NN ~= 0 % epidermis for
%the gold standard, epidermis for the NN (true positive)
TP = TP + 1;
end
end
end
%added for security so if program crashes data can still be retrieved
%from the images however will have to calculate accuracy, specificity
%and sensitivity by hand
fprintf("Image Number = %d\t", j);
fprintf("True Positive = %d\t", TP);
fprintf("True Negative = %d\t", TN);
fprintf("False Positive = %d\t", FP);
fprintf("False Negative = %d\n", FN);
end
%checks for accuracy, specificity and sensitivity
acc = (TP + TN)/(TP + TN + FP + FN);
spec = (TN)/(TN + FP);
sens = (TP)/(TP + FN);
%prints off Values
fprintf("Accuracy = %f\t", acc)
fprintf("Specificity = %f\t", spec);
fprintf("Sensitivity = %f\t", sens);
However is recive this error:
Error using imread>get_format_info
Unable to determine the file format.
Error in imread/call_format_specific_reader (line 460)
fmt_s = get_format_info(fullname);
Error in imread (line 434)
[X, map] = call_format_specific_reader();
Error in SPOT_ConfusionMatrixCreator (line 26)
im_NN = imread(full_dir_NN);
I am confused since the files have the ending .tif as shown below

Answers (1)

Ryan Baird
Ryan Baird on 15 Mar 2023
Do the 4 bytes at the beginning of the files' data match one of the numbers defined by the tif file format?
If not, and if that's the only thing wrong with the files, you might be able to bypass the file format detection by manually specifying the file format:
imread(full_dir_NN, 'tif');

Community Treasure Hunt

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

Start Hunting!