i tryng to run a .m file but always shows a error undefined variable.... plz help

1 次查看(过去 30 天)
errror : Undefined variable "cropping" or class "cropping.m".
The cropping.m file is : %===============================================================================
function[out,check] =cropping_fun(image, x_TopLeft, y_TopLeft, x_BottomRight, y_BottomRight)
check=0;
clc; close all;
% let us handle cases if the user inputs incorrect or insufficient inputs
if nargin>0 if (ischar(image))&&(exist(image, 'file')==2)
A=double(imread(image));
elseif exist('image', 'var')
A=double(image);
end
size_A=size(A);
end
if nargin==0 A=double(imread('D:\\Thesis Code\\Source Code\\StegoImage.png'));
size_A=size(A);
x_TopLeft=ceil(size_A(1)/4);
y_TopLeft=ceil(size_A(2)/4);
x_BottomRight=floor(3*size_A(1)/4);
y_BottomRight=floor(3*size_A(2)/4);
elseif nargin==1
x_TopLeft=ceil(size_A(1)/4);
y_TopLeft=ceil(size_A(2)/4);
x_BottomRight=floor(3*size_A(1)/4);
y_BottomRight=floor(3*size_A(2)/4);
elseif nargin==2
y_TopLeft=ceil(size_A(2)/4);
x_BottomRight=floor(3*size_A(1)/4);
y_BottomRight=floor(3*size_A(2)/4);
elseif nargin==3
x_BottomRight=floor(3*size_A(1)/4);
y_BottomRight=floor(3*size_A(2)/4);
elseif nargin==4
y_BottomRight=floor(3*size_A(2)/4);
end
%==========================================================================
% size of the cropped image
M=x_BottomRight-x_TopLeft+1; N=y_BottomRight-y_TopLeft+1;
%==========================================================================
% Memory allocation for the output image for faster implementation of the % code
image_dim=size(size_A);
if image_dim(2)==3 P=3; B=zeros(M, N, P); else B=zeros(M, N); end
%==========================================================================
if ((M>0)&&(N>0))
for i=1:M
for j=1:N
B(i, j, :)=A(x_TopLeft+i, y_TopLeft+j, :);
end
end
new_imagesc(A);
title('Original image');
new_imagesc(B);
title('Cropped image');
else
error('Check the dimensions of the cropped image.');
end
end % End of the cropping_fun
%==========================================================================
function new_imagesc(A)
%==========================================================================
% Author: Prashant Athavale % Date 11/19/2011 % Please acknowledge my name if you use this code, thank you. % This is a function to display images at the center of the screen using % Matlab's imagesc function
%==========================================================================
figure; screen_size=get(0,'screensize'); screen_width=screen_size(3); screen_height=screen_size(4); figure_width=screen_size(4)/2; % width of the figure figure_height=screen_size(4)/2; % height of the figure x_lowerbottom=(screen_width-figure_width)/2; y_lowerbottom=(screen_height-figure_height)/2; set(gcf,'position',[x_lowerbottom y_lowerbottom figure_width figure_height]); image_dim=size(size(A));
% What to do if the image is color/RGB or grayscale
if image_dim(2)==3 M=max(max(max(A))); elseif image_dim(2)==2 M=max(max(A)); end
if M>1
M=1;
else
M=255;
end
% imagesc likes the images from 0 to 255 % if they are not then we make them so.
A=double(A); imagesc(uint8(A*M)); if image_dim(2)==3 colormap('colormap'); else colormap('gray'); end
end % end of function new_imagesc
%==========================================================================

回答(1 个)

Image Analyst
Image Analyst 2014-11-25
Read this so you'll know how to format your code. Then rename your m-file so that it has the same name as your function, cropping_fun.m. See if that helps.

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by