필터 지우기
필터 지우기

Error undefined function while it is already defined

조회 수: 2 (최근 30일)
Ali Purse
Ali Purse 2018년 10월 25일
편집: Stephen23 2018년 10월 25일
Hi
I got undefined function while using the following function:
function nearest_neighbor_zoom(file,fac)
im=imread(file);
[h,v]=size(im);
for i=1:h
for j=1:v
im1( floor(1+(i-1)*fac), floor(1+(j-1)*fac),:)=im(i,j); %mapping pixels of given image to a new array so that zooming factor is satisfied.
end
end
[h1,v1]=size(im1);
disp('Unknown pixel values are being interpolated. Look at Figure1');
%nearest neighbor interpolation
for i=1:h1-1
for j=1:v1-1
if( (floor( 1+( ceil((i-1)/fac+1) -1)*fac )==i) && ( floor( 1+( ceil((j-1)/fac+1) -1)*fac )==j ) ) % maped values from the original picture should not be recalculated.
else %for pixels that should be calculated
if(floor( 1+( ceil((i-1)/fac+1) -1)*fac )==i) %on a defined vertical level
xo00=ceil((i-1)/fac+1);
x00=i;
else
xo00=floor((i-1)/fac+1);
x00=floor(1+(xo00-1)*fac);
end
if( floor( 1+( ceil((j-1)/fac+1) -1)*fac )==j )%on a defined horizontal level
yo00=ceil((j-1)/fac+1);
y00=j;
else
yo00=floor((j-1)/fac+1);
y00=floor(1+(yo00-1)*fac);
end
xo10=xo00+1;
yo10=yo00;
x10=floor(1+(xo10-1)*fac); %current coordinate of 10;
y10=floor(1+(yo10-1)*fac);
xo01=xo00;
yo01=yo00+1;
x01=floor(1+(xo01-1)*fac); %current coordinate of 01;
y01=floor(1+(yo01-1)*fac);
xo11=xo10;
yo11=yo01;
x11=x10; %current coordinate of 11;
y11=y01;
xlen=x11-x00;
ylen=y11-y00;
x=i-x00;
y=j-y00;
dx=x/xlen; %converting coordinates of the pixel being calculated to (0*1)(0*1) domain.
dy=y/ylen;
if dx<=0.5 %if the pixel being calculated is near to the known upper pixel level.
nx=0;
else %to known lower pixel level.
nx=1;
end
if dy<=0.5 %if the pixel being calculated is near to the known left pixel level.
ny=0;
else %to known right pixel level.
ny=1;
end
if ((nx==0) &&(ny==0)) %assigning the upper left known pixel to the pixel being calculated.
h00=im1(x00,y00,:);
im1(i,j,:)=h00;
elseif ((nx==1) && (ny==0)) %assigning the lower left known pixel to the pixel being calculated.
h10=im1(x10,y10,:);
im1(i,j,:)=h10;
elseif((nx==0) && (ny==1)) %assigning the upper right known pixel to the pixel being calculated.
h01=im1( x01,y01,:);
im1(i,j,:)=h01;
elseif((nx==1)&&(ny==1)) %assigning the lower right known pixel to the pixel being calculated.
h11=im1(x11,y11,:);
im1(i,j,:)=h11;
end
end
end
imshow(im1); %displaying image being interpolated.
end
disp('Zooming is complet. Look at Figure1');
imshow(im1);
imwrite(im1,'zoomed_pic.jpg');
end
The error is:
Undefined function or variable 'nearest_neighbor_zoom'.
May you please help me how to fix the problem?
Thank you
  댓글 수: 1
Stephen23
Stephen23 2018년 10월 25일
편집: Stephen23 2018년 10월 25일
Where have you saved nearest_neighbor_zoom ? Is that folder on the MATLAB Search Path?:
Have you saved the Mfile with the same name as the function?

댓글을 달려면 로그인하십시오.

답변 (2개)

madhan ravi
madhan ravi 2018년 10월 25일
편집: madhan ravi 2018년 10월 25일
Replace nearest_neighbor_zoom with nearest_neighbor_zoom1 and see if the error persists , if it does
there is already a function with the same name if so please rename or delete (if necessary).

Wajahat Muhammad
Wajahat Muhammad 2018년 10월 25일
Have you saved the file as the function name.File name should be same as function name.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by