Connect centroids horizontally and detect missing objects.

7 views (last 30 days)
The task is to connect the centroids that I have got using regionprops horizontally in rows and then predict missing objects.
Here is the image that I have after getting boundaries and centroids:
This is what I want to achieve :
All centroids within a certain y-coordinate range should be connected. After that I want to predict the missing objects. For example, there should be more objects/centroids present on the green line in the image above.
My code so far :
BW = rgb2gray(imread('noise_removal_single_25_cropped.png'));
props = regionprops(im2bw(BW), 'Centroid');
centroids = cat(1, props.Centroid);
[B,L] = bwboundaries(BW,'noholes');
imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2)
end
plot(centroids(:,1),centroids(:,2), 'b*')
plot(centroids(:,1),centroids(:,2), 'k-')
The code connects all centroids vertically and I have no idea how to detect missing objects/centroids (maybe based on length of line)?

Answers (1)

Image Analyst
Image Analyst on 8 Jul 2016
Edited: Image Analyst on 8 Jul 2016
The code DOES NOT "connects all centroids vertically" - I don't know why you think it does.
If you sum the binary image horizontally and threshold, you can find out what the y regions are that have lines of writing in them. Then, for each y region, find the indexes of all labeled blobs that have y centroids in that range. Then sort those by their x centroid values so that now you have blobs going from left to right on a particular line.
Then for each blob on a particular line, draw a line to the previous blob. Start with the 2nd left most blob, and draw a line to the center of the left most, and so on until you end up on the right most blob.
Please give it a try. You're a smart engineer so I know you know how to use functions like sort() and how to use > and < to select ranges. I can give you the attached demo for how to burn a line into an image if you want, but I don't have any code to do all that you asked and what I described. Anyway, you didn't attach the binary image even if I were to do it. But you should be able to finish it by yourself in about 15 - 30 minutes or so. Good luck.
  4 Comments
downingstreet
downingstreet on 25 Jul 2016
Edited: downingstreet on 25 Jul 2016
Detecting the rows of plants and then telling where a plant is missing. The green objects in the image are the plants (corn).
Image Analyst
Image Analyst on 25 Jul 2016
Use color segmentation to find the green plants. Then maybe use a template to specify row locations or try to figure it out from the image (if enough plants are there) by using hough(). Then use regionprops to get the plant centroids and for each centroid in a row, determine if the x coordinate of a plant is too far away from the neighboring plant. If so, a plant is missing.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!