insertshape auto find the coordinate of the object

Hi, may i know how to insertshape auto find the coordinate of the object that in black pixel in the image?
Capture.JPG

 Accepted Answer

info = regionprops(~TheImage, 'Centroid');
coords = vertcat(info.Centroid);
x_coords = coords(:,1);
y_coords = coords(:,2);
but remember that x corresponds to columns and y corresponds to rows.

2 Comments

This is my coding, so this part will put at where?
clear all
% read original image
a = imread('pcb2.jpg');
imshow(a)
% read test image
b = imread('pcb2_openckt.jpg');
imshow(b)
% subtraction
c = imabsdiff(a,b)
imshow(c)
d = imcomplement(c)
imshow(d)
% to find the coordinate of the object from d
f = insertShape(a,'circle',[33 20, 20],'LineWidth',5);
subplot(3,3,1), imshow(a), title('Original')
subplot(3,3,2), imshow(b), title('Test')
subplot(3,3,3), imshow(c), title('Difference')
subplot(3,3,4), imshow(d), title('Inverted Difference')
subplot(3,3,5), imshow(f), title('Labeled')
isertShape does not "find" regions in an image. Finding regions is what regionprops() does.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!