How to Detect Shape in Image MATLAB

41 views (last 30 days)
Med Future
Med Future on 5 Apr 2022
Commented: Med Future on 5 Apr 2022
I want to Detect the shape in image
I have the following two image in one image i have Normal Shape and in second image i have shape with noise
I have the following code which works well on im_002317.png as shown in untitled.png attached.
But when i added Noise to that line the values changes as in image im_002017.png
The shape is not detected well.
How can i modified the code to detect the same shape
Or How can i draw bounding box on each level to detect the whole shape
rgbImage = imread('Noise\im_002017.png');
[rows, columns, numberOfColorChannels] = size(rgbImage);
if numberOfColorChannels > 1
grayImage = rgbImage(:, :, 3);
grayImage = rgbImage;
mask = grayImage >= 128;
[labeledImage, numRegions] = bwlabel(mask);
props = regionprops(labeledImage, 'Area', 'Centroid','BoundingBox');
allLengths = [props.Area];
centroids = vertcat(props.Centroid);
whiteLineRows1 = centroids(:, 2);
DSPRFValue= unique(whiteLineRows1);
hold on;
for k = 1 : numRegions
y1 = centroids(k, 2);
y2 = y1;
xt = props(k).Centroid(1);
yt = props(k).Centroid(2);
BB = props(k).BoundingBox;
str = sprintf('Pulse Length %d at PRF %d', allLengths(k), y1);
xlim([0 1000]);
text(xt, yt, str, 'Color', 'r', 'HorizontalAlignment', 'Center', 'VerticalAlignment','bottom', 'FontSize',8);
rectangle('Position', [BB(1),BB(2),BB(3),BB(4)],'EdgeColor','b','LineWidth',1) ;
caption = sprintf('Dwell and Swtich Image with %d Levels', Levels);
hold off
title(caption, 'FontSize',10);

Answers (0)


Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by