What's wrong with this code?

1 次查看(过去 30 天)
Every time I run this code an error message appears saying '??? undefined function or method 'img' for input arguments of type 'char'.' I am attempting to view a coded image. What is the problem? Thanks,
clear all; clc;
[FileName,path] = uigetfile({'*.img'},'Choose ASL Label File');
k = length(FileName);
file = FileName(1:(k-4));
filenameh=strcat(path,FileName(1:(k-3)),'hdr');
fidh = fopen(filenameh,'r','b');
fseek(fidh,40,'bof');
fseek(fidh,40,'bof');
dim = fread(fidh,8,'int16');
hdrsize = fread(fidh,1,'int32','l');
if hdrsize == 348
datatype = 'l';
else
datatype = 'b';
end
data_format=fread(fidh,8,'int16',datatype);
if data_format(6)==4
form = 'short';
elseif data_format(6) ==16
form = 'float';
else
disp('Problem Reading In File')
quit cancel
end
xdim = dim(2);ydim = dim(3);zdim = dim(4);vols = dim(5);
disp('Analysing ....')
lab1f = strcat(path,file,'.img');
l1fid=fopen(lab1f,'r',datatype);
lab1=fread(l1fid,form);
lab1=reshape(lab1,xdim,ydim,zdim,vols);
  2 个评论
Geoff Hayes
Geoff Hayes 2014-7-5
Jack - if including code in your question (instead of attaching it using the paper clip button) please ensure that it is formatted correctly to improve readability. Highlight the code portions of the question and press the {} Code button.
The undefined function or method message typically means that the code is using something as a function which is not defined or found in the MATLAB search path, or it is invalid for inputs of a certain type. Your error message is for something called img which I don't see anywhere in your code except as a file extension.
Have you included all the code relevant to this question? What is the line number that has generated this error?
Image Analyst
Image Analyst 2014-7-5
Please include the entire error message - ALL THE RED TEXT - don't snip or paraphrase it at all. By leaving out vital information (so far), you've prevented anyone from pinpointing and fixing your error.

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2014-7-5
I’m not aware that ‘.img’ is a valid format in MATLAB. (I can’t find any reference to it, anyway.) You need to use the iminfo function to find out what its format is, and then read it with imread. You can then extract the data you need from the array created by imread. There are many other functions in the Image Processing Toolbox if you have access to it.
  5 个评论
Jack
Jack 2014-7-7
It's been resolved, sorry for the confusion but its a very old script. Issue was with file name, it included spaces. Thanks for all your help.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Low-Level File I/O 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by