MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

# How to solve the error?

Asked by Shaila parvin on 26 May 2013

when I run the code:

```function [shape] = Classify(ImageFile)
GRAY = rgb2gray(RGB);
else
RGB=GRAY;
end
```
```threshold = graythresh(GRAY);
BW = im2bw(GRAY, threshold);
```
```%Invert the Binary Image
BW = ~ BW;
[~,L] = bwboundaries(BW, 'noholes');
```
```STATS = regionprops(L,'all');
```
```for i=1:length(STATS)
```
```if norm([STATS(i).Extrema(2,1), STATS(i).Extrema(2,2)]-[STATS(i).Extrema(1,1), STATS(i).Extrema(1,2)])<5 %TR,TL
%can be triangle hexagon pentagon
if norm([STATS(i).Extrema(4,1), STATS(i).Extrema(4,2)]-[STATS(i).Extrema(3,1), STATS(i).Extrema(3,2)])<5 %RT,RB
%can be pentagon triangle
if  norm([STATS(i).Extrema(4,1), STATS(i).Extrema(4,2)]-[STATS(i).Extrema(5,1), STATS(i).Extrema(5,2)])<5 %RT,RB,BR = Triangle
shape(i,1)=1; % Triangle
else
shape(i,1)=3; % Pentagon
end
else
shape(i,1) = 4; % hexagon
end
elseif (STATS(i).MajorAxisLength/STATS(i).MinorAxisLength<1.1 && STATS(i).Eccentricity <0.5 || (STATS(i).Solidity/STATS(i).Extent)==1)&(STATS(i).Area<0.1*numel(GRAY))
shape(i,1)=2; % Rectangle
else
shape(i,1)=0;
end
end
```
```if ~isempty(find(shape==2))
disp('Rectangle found');
else
disp('No rectangle in the image')
end
```
```return
```

I've the error "??? Input argument "ImageFile" is undefined.

Error in ==> Classify at 3 if ndims(imread(ImageFile))>2"

How to solve it?

## Products

No products are associated with this question.

Answer by Azzi Abdelmalek on 26 May 2013
Edited by Azzi Abdelmalek on 26 May 2013

How did you run this code?

This file is a function, it should be called: in the windows Matlab command, type

```shape = Classify(ImageFile)
```

Look at Function

Shaila parvin on 26 May 2013

this shape function will be called from Classify.m file. Right?

Shaila parvin on 26 May 2013

BW = ~ BW;

What does it mean?

Jan Simon on 26 May 2013

@Sahila parvin: This toggles the value of the black&white pixels.

Answer by Image Analyst on 26 May 2013

Put this at the beginning of your function:

```if nargin < 1
[baseFileName, folder] = uigetfile();
ImageFile = fullfile(folder, baseFileName);
end
```

Shaila parvin on 26 May 2013

my basefile is circle.jpg and folder is E:\4-1\image-thesis\implementation\shaila

what I've to write?

if nargin < 1

```[circle.jpg, E:\4-1\image-thesis\implementation\shaila] = uigetfile();
```
```ImageFile = fullfile(E:\4-1\image-thesis\implementation\shaila, circle.jpg);
```

end