I have the following code:
clc;clear all;% This part reads and shows the image selected
I = imread('115.2.jpg');imshow(I)% Ginput is used to select the Hinge position
[x,y] = ginput(1)% drawpoint is used to mark the Hinge position
h = drawpoint('Position',[x y]); % Convert the RGB image to a Grayscale image
G=im2gray(I);level = graythresh(G)% Binarize the grayscale image
BW = imbinarize(G,level);% Display the Grayscale image
figure title('Grayscale Image')imshow(G)% Display the Binarized image
figure title('Binarized')imshow(BW)% Fill holes
BW2 = imfill(BW,'holes');% Display the Image after filling holes
figure imshow(BW2)title('Filled Image')% Mark the Hinge here as well
h = drawpoint('Position',[x y]);imwrite(BW2, 'BW2.jpg')% Find the centroid
measurements = regionprops(BW2, 'Centroid');imshow(BW2);centroids = cat(1,measurements.Centroid);hold on;plot(centroids(:,1), centroids(:,2), 'r+', 'MarkerSize', 30, 'LineWidth', 1);hold off;
where the image 115.2 is
And on running that code, I get:
How do I find the coordinates of the centroid of the rectangular blob? How do i neglect all centroids except the centroid of the rectangular blob?
Best Answer