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!