Find index position of the second last '1' per row in a BW image

1 vue (au cours des 30 derniers jours)
paloma paleo
paloma paleo le 9 Nov 2021
Commenté : paloma paleo le 9 Nov 2021
I have a image (or matrix) with only '0' and '1'.
I need to find the index of the second last of '1' in each row.
The matrix (E) is the result of finding the profile of a BW image.
[E,th]=edge(BW,'canny'); %profile of the image.
surface = accumarray(row,col,[size(E,1),1],@max,NaN); %this gives the maximum index per row but I need the second maximum.

Réponses (2)

Image Analyst
Image Analyst le 9 Nov 2021
Try this to find the last column in each row that is true for your binary image
[rows, columns] = size(E)
lastColumns = zeros(1, columns);
for row = 1 : rows
% Scan down row-by-row.
thisRow = E(row, :);
% Find last true value
r = find(thisRow, 1, 'last'); % Will be empty if there are no white pixels in that row.
if ~isempty(r)
% There is at least one white pixel in that row,
% so record its position.
lastColumns(row) = r;
end
end
If you need starting and stopping columns for each of the blobs, you will have a problem and may need to take a different approach. That's because you can't simply fill the outlines because some of your outlines are broken/open and can't be filled so you can't just use find(thisRow) and take all the even numbered indexes. You may need to reevaluate whether Canny is something you really need to do. In most cases edge detection is not the best approach but I'd have to see your original image.

paloma paleo
paloma paleo le 9 Nov 2021
The original images are grey images. I am analysing thousends of images.
There is a liquid falling down a flat surface and I need to see the profile (yelow lines in the samples).
I can see with my eye the profile but it is really difficult to create a script that automatically can find that profile.
I have tried so many alternatives but nothing seems to be working.

Community Treasure Hunt

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

Start Hunting!

Translated by