MATLAB: How to detect or identify the middle row of the crops by hough()

image processingImage Processing Toolboximage segmentation

456.jpg

Best Answer

I don't think you need hough. You can simply use regionprops() and ask for centroid and orientation. You can then use ismember on the labeled image to extract either
  1. the blob with the most vertical orientation, OR
  2. the blob with the x centroid closest to the middle of the image.
Hopefully those are the same blob - I think they will be for the example you posted. Starting with your segmented, binary image, it goes something like this:
labeledImage = bwlabel(binaryImage);
props = regionprops(labeledImage, 'Centroid', 'Orientation');
% Find blob based on angle
diffAngles = abs([props.Orientation] - 90);
[minAngleDiff, index] = min(diffAngles);
centerBlob = ismember(labeledImage, index);
% Find blob based on centroid
[rows, columns] = size(binaryImage)
xyCentroids = vertcat(props.Centroid);
xCentroids = xyCentroids(:, 1);
diffx = abs(xCentroids - columns/2);
[minXDiff, index] = min(diffx);
centerBlob2 = ismember(labeledImage, index);
I haven't tested that. It's just off the top of my head. If you run into trouble, write back.