How can I perform feature detection on an image?

5 views (last 30 days)
I have an image and wish to programmatically locate certain features/patterns.  Does MATLAB have the functionality to do this?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 7 Apr 2015
The Image Processing Toolbox has several functions that, when used together, can identify user-defined patterns in masked images.  While there are many different ways of accomplishing this in MATLAB.  The following example is a simple method that can be applied in many cases:
 
im1 = imread('image.png');
% binary matrix containing the outline of the desired feature etched out by 1's
mask = [...];
se = strel('arbitrary', mask);
% apply a Sobel filter to the image which highlights the edges
im_f = edge(im1, 'sobel');
% filter the image using the stencil mask, if the stencil is good, it will
% only retain mask-shaped features in the Solbel-filtered image
im_er = imerode(im_f, se);
% enhance the features from the eroded image
im_di = imdilate(im_er, se);
% get the "center of mass" of each individual object in the enhanced,
% filtered image -- this works best if the original image was converted to
% black and white
rp = regionprops(im_di,'centroid');
After executing this example, the "rp" variable will contain the centroid locations of each instance of the feature described by "mask".  Typically, "mask" is determined experimentally to achieve the desired results.

More Answers (0)

Products


Release

R2013a

Community Treasure Hunt

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

Start Hunting!