Borrar filtros
Borrar filtros

What's wrong with this code?

1 visualización (últimos 30 días)
Jack
Jack el 4 de Jul. de 2014
Comentada: Star Strider el 7 de Jul. de 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 comentarios
Geoff Hayes
Geoff Hayes el 5 de Jul. de 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
Image Analyst el 5 de Jul. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 5 de Jul. de 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 comentarios
Jack
Jack el 7 de Jul. de 2014
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.
Star Strider
Star Strider el 7 de Jul. de 2014
My pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by