Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How to perform an image classification ?

Asked by Chaou on 14 Apr 2013

Hello. I have plenty of images, each one of them corresponds to a class. Knowing that I have 3 classes, I want to perform an image classification. I'm used to SVM and others, and I know how to perform the training and classification.

How do I proceed to the feature extraction from an image ?

Thank you!

0 Comments

Chaou

6 Answers

Answer by Image Analyst on 14 Apr 2013

Once you have the classified image, you essentially have a labeled image. 0 = background, a value of 1 = class 1, and so on. If you want all blobs of a certain class to be measured as a group, then just call regionprops.

groupMeasurements = regionprops(classifiedImage, 'all');

If you want each blob for a certain class to be measured by itself, then turn it into a binary image and then call regionprops:

binaryImage = classifiedImage == theClassNumberYouWant;

Then call regionprops:

individualBlobMeasurements = regionprops(binaryImage, 'all');

See my "BlobsDemo" for a more comprehensive tutorial: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

0 Comments

Image Analyst
Answer by Anand on 15 Apr 2013

There are a bunch of different feature extraction approaches that are tied to what kind of images you have and the kind of problem you are attempting to solve. Here are some common feature descriptors you could extract: SURF features,MSER regions,FAST corners, Minimum Eigen Value corners and Harris corners.

Guess what, they are all in the Computer Vision System Toolbox!

Use the following functions to detect them:

detectFASTFeatures

detectSURFFeatures

detectHarrisFeatures

detectMSERFeatures

detectMinEigenFeatures

and this function to extract them:

extractFeatures

1 Comment

Chaou on 30 Apr 2013

Thank you for your answers! I'm dealing with this error when I run detectFASTFeatures, or any else command cited above. I put my image in the variable 'x'. He is the error:

>> size(x)

ans =

   576   720     3
>> corners = detectFASTFeatures(x); Undefined function 'detectFASTFeatures' for input arguments of type 'uint8'.

Can you help me, please?

Anand
Answer by Image Analyst on 30 Apr 2013

Did you see the help:

"points = detectFASTFeatures(I) returns a cornerPoints object, points. The object contains information about the feature points detected in a 2-D grayscale input image, I. "

You have a 3D image - a color image. The help says that it needs to be a 2D grayscale image. Either take one color channel

grayImage = x(:,:,2);

or a weighted average of the color channels:

grayImage = rgb2gray(x);

The first method is preferable.

0 Comments

Image Analyst
Answer by Chaou on 1 May 2013
Edited by Chaou on 1 May 2013

Hello. This is an example of 3-D images I want to work on. This image described an electrical discharge. Basically, I want to make an image recognition system able to detect near occurring discharge (as in this image), or not.

When I take one color channel, by runing this command:

grayImage = x(:,:,2);

I obtain this image:

Here are some problems, First, the 2-D image obtained does not describe the electrical discharge. Second one, even if I run this cornerPoints of the 2-D image, it still not working. It displays this message again:

*>> points = detectFASTFeatures(grayImage)* Undefined function 'detectFASTFeatures' for input arguments of type 'uint8'.

Even if I use an image from matlab library, just like this:

*>> I = imread('cameraman.tif');* *>> corners = detectFASTFeatures(I);* Undefined function 'detectFASTFeatures' for input arguments of type 'uint8'.

Can you help me, please? I would really appreciate it! :)

1 Comment

Image Analyst on 1 May 2013

That pseudocolored image does not make sense. Even ignoring the colormap it doesn't look anything like what it should. You should see a bright band running through that glass slide or panel or whatever it is. What does it look like if you do

imshow(grayImage, []);

Plus you need to upload an image with no discharge, and one with full discharge, and maybe one or two more with "nearly occurring discharge" so I can see what it is that distinguishes the nearly occurring discharge from the full or no discharge image.

Chaou
Answer by Chaou on 5 May 2013
Edited by Chaou on 5 May 2013

Hello. As you requested, here are the images corresponding to no discharge, few discharges and a lot of discharges (before flash-over).

-

-

How can I extract features to detect those discharges? Thank you so much!

1 Comment

Image Analyst on 5 May 2013

Why don't you just get the mean gray level between certain rows? It looks like that should correlate pretty well with the level of discharge. Of course you'll want to turn off the automatic gain or exposure control in your camera because you can't have the camera trying to reduce the exposure when the image is supposed to be brighter. I can tell you have some sort of automatic gain or exposure because the intensity of the shaft on the bottom is different in the images.

Chaou
Answer by Chaou on 18 May 2013
Edited by Chaou on 18 May 2013

Hello Image Analyst, I think that the problem is bigger. I can't even execute the Matlab tutoriel for finding corners. http://www.mathworks.com/help/vision/ref/detectfastfeatures.html#btoe5z2-2

>> I = imread('cameraman.tif');

>> corners = detectFASTFeatures(I);

Undefined function 'detectFASTFeatures' for input arguments of type 'uint8'.

How can I get rid of this error? Thank you so much.

4 Comments

Chaou on 18 May 2013

Hello, here is what I get when I type the code you gave me:

>> which detectFASTFeatures
ver
'detectFASTFeatures' not found.
-------------------------------------------------------------------------------------------------------
MATLAB Version: 7.14.0.739 (R2012a)
MATLAB License Number: 
Operating System: Microsoft Windows 7 Version 6.1 
Java Version: Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode
-------------------------------------------------------------------------------------------------------
MATLAB                                                Version 7.14       (R2012a)                     
Simulink                                              Version 7.9        (R2012a)                     
Aerospace Blockset                                    Version 3.9        (R2012a)                     
Aerospace Toolbox                                     Version 2.9        (R2012a)                     
Bioinformatics Toolbox                                Version 4.1        (R2012a)                     
Communications System Toolbox                         Version 5.2        (R2012a)                     
Computer Vision System Toolbox                        Version 5.0        (R2012a) 

I don't understand. detectFASTFeatures belongs to the Computer Vision System Toolbox (which is present in my Matlab, see the last line in code) . Why can't matlab find the detectFASTFeatures function?

Image Analyst on 18 May 2013

I don't know. I don't have that toolbox. You might have to call them on Monday. Maybe your path is messed up. Did you do anything to your path? Can you search your hard drive in the toolbox subfolder of MATLAB for it?

Chaou on 20 May 2013

I didn't touch anything on the Matlab Path. I tried those function on my friend's laptop. It displays the same error as mine. I tried to convert the image from uint8 to Double, like this:

I = imread('cameraman.tif');
I2 = im2double(I)
corners = detectHarrisFeatures(I2);
Undefined function 'detectHarrisFeatures' for input arguments of type 'double'.
Chaou

Contact us