How to Detect Shape in Image MATLAB
8 次查看(过去 30 天)
显示 更早的评论
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
im_002317.png
im_002017.png
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);
else
grayImage = rgbImage;
end
mask = grayImage >= 128;
[labeledImage, numRegions] = bwlabel(mask);
props = regionprops(labeledImage, 'Area', 'Centroid','BoundingBox');
allLengths = [props.Area];
NumberofPulses=allLengths;
centroids = vertcat(props.Centroid);
whiteLineRows1 = centroids(:, 2);
DSPRFValue= unique(whiteLineRows1);
Levels=length(DSPRFValue);
figure;
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) ;
PRFValue(k)=y1;
caption = sprintf('Dwell and Swtich Image with %d Levels', Levels);
hold off
title(caption, 'FontSize',10);
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!