What's wrong with this code?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jack
am 4 Jul. 2014
Kommentiert: Star Strider
am 7 Jul. 2014
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 Kommentare
Geoff Hayes
am 5 Jul. 2014
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
am 5 Jul. 2014
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.
Akzeptierte Antwort
Star Strider
am 5 Jul. 2014
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 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!