- First of all you need to binarize the image and find edges of image using canny edge detection.
- Then you need use regionprops to extract various isolated regions in the image.
- You need to find centroid of regions.
- Then at various angles, you can find distance between centroid of region and point on edge of image.
- This makes your shape descriptors.
- You can compare these descriptors with descriptors of known share to categorize your query or unkown object.
Matlab code for extract shape features from an image including circle and rectangle
31 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tamara Ahmed
el 27 de Mayo de 2021
Comentada: Amit
el 5 de Jun. de 2021
Hello, I have a project that goes beyond image processing in matlab. I need the special code to extract shape properties from images using Hog and regionprops, noting that the image contains a rectangle and a circle. I will attach an image as an example. The images whose properties are to be extracted are the words encoded by Morse code
1 comentario
Amit
el 5 de Jun. de 2021
Follow following steps,
This should work for you.
I have my IEEE paper published regarding above process, you can send request to me on, amit.kenjale@gmail.com, I will send you my IEEE paper where this process is explained in details with images showing intermediate results.
Respuesta aceptada
darova
el 27 de Mayo de 2021
Just binarize the image
A = imread('5C54390E-80C8-47DD-9293-822E85D06145.jpeg');
A1 = im2bw(A);
L = bwlabel(~A1); % label each region
s = regionprops(L,'area'); % find area of each region
ar = cat(1,s.Area);
[~,n] = min(ar); % find minimum area (circle)
imshow(L==n) % find index with minimum area and show
3 comentarios
darova
el 28 de Mayo de 2021
Calculate minimum area (smallest circle)
[~,n1] = min(ar); % find minimum area (circle)
Calculate maximum area (biggest rectangle)
[~,n2] = max(ar); % find maximum area (rectangle)
Find average value
n = (n1+n2)/2;
Find all areas smaller than average
n = ar < n;
Show all circles
A2 = A1*0; % preallocate
for i = 1:length(n)
A2 = A2 | (L==n(i));
end
imshow(A2)
Más respuestas (1)
Image Analyst
el 28 de Mayo de 2021
I know you already have accepted an answer, but I thought you might like to see my approach.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
folder = pwd;
baseFileName = 'morse code.jpeg';
grayImage = imread(baseFileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage = min(grayImage, [], 3);
end
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(1, 2, 1);
imshow(grayImage, []);
axis('on', 'image');
title('Reference Image', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
hFig = gcf;
hFig.WindowState = 'maximized'; % May not work in earlier versions of MATLAB.
%--------------------------------------------------------------------------------------------------------
% Binarize the image.
% Get a mask of the dark parts in the image.
% imhist(image1);
% grid on;
mask = ~imbinarize(grayImage);
% Get rid of noise by eliminating blobs smaller than 4000 pixels.
mask = bwareaopen(mask, 4000);
subplot(1, 2, 2);
imshow(mask, []);
axis('on', 'image');
title('Mask Image', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
drawnow;
%--------------------------------------------------------------------------------------------------------
% Measure areas
props = regionprops(mask, 'Area', 'Centroid');
allAreas = [props.Area]
%--------------------------------------------------------------------------------------------------------
% Plot what it is over the original image.
subplot(1, 2, 1);
for k = 1 : length(props)
xCenter = props(k).Centroid(1);
yCenter = props(k).Centroid(2);
if allAreas(k) > 9600
blobType = 'dash';
else
blobType = 'dot';
end
text(xCenter, yCenter, blobType, 'Color', 'r', ...
'FontWeight', 'bold', 'FontSize', 18, ...
'HorizontalAlignment', 'center',...
'VerticalAlignment', 'middle');
end
% Get an array where 1 is dash and 0 is dot
dotOrDash = allAreas > 9600
msgbox('Done');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/633900/image.png)
See the identification labeled in red over the image.
You get:
dotOrDash =
1×4 logical array
1 1 0 1
Is this what you are looking for?
4 comentarios
Image Analyst
el 4 de Jun. de 2021
Not really. The accepted answer says this:
s = regionprops(L,'area'); % find area of each region
ar = cat(1,s.Area);
while mine says this:
% Measure areas
props = regionprops(mask, 'Area', 'Centroid');
allAreas = [props.Area]
Those are essentially the same - they both give the area of all the blobs in the image. Not sure what your definition of "shape" is but both of our solutions characterize based on area alone. The difference is the accepted answer only extracts and gives you the area of the smallest blob, while mine characterizes every single blob. Neither answer distinguishes between blobs on the basis of shape, other than different shapes have different areas. If the area of the dot and dash were identical, then we would not be able to distinguish the type by area - we'd have to use a different metric, like EquivDiameter, MajorAxisLength, or circularity or something else.
I don't want to sound like I'm arguing with you -- I just want to make sure you understand what the programs do (his finds the smallest shape only, and mine characterize all shapes) because it seems like you think darova's answer gives you something more than it actually does. His finds one shape (the smallest) and does not determine whether it's a circular or rectangular shape, while mine finds all four shapes and does determine the shape for all four shapes in the image. With my code, you could have a look up table of letters and patterns so you could look up the pattern (that I called dotOrDash) to determine the letter corresponding to that Morse Code pattern.
Ver también
Categorías
Más información sobre Geometric Transformation and Image Registration en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!