Error using imfinfo()

17 views (last 30 days)
Matt Morrison
Matt Morrison on 22 Apr 2020
Answered: Walter Roberson on 22 Apr 2020
Every time I run this code it says that for some reason there is an error in line 142 of the function imfinfo:
filename=uigetfile('*.tif');
[r c]=size(imfinfo(filename));
for i = 1:r
rgb = imread(filename, i);
set(handles.textSlidenumber, 'String', i);
status = get(radiobuttonRBG, 'Value');
if status
imshow(rgb);
else
gray = rgb2gray(rgb);
imshow(gray);
end
line 142 in imfinfo is:
error(message('MATLAB:imagesci:imfinfo:fileOpen', filename));

Answers (1)

Walter Roberson
Walter Roberson on 22 Apr 2020
filename=uigetfile('*.tif');
The output you get from that call will not include any directory information. If the user chooses something that is not in the current directory, you will have difficulty.
[filename, pathname] = uigetfile('*.tif');
if ~ischar(filename)
%user canceled
return
end
filename = fullfile(pathname, filename);

Categories

Find more on Numeric Types 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!