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

2 次查看(过去 30 天)
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.

回答(2 个)

Image Analyst
Image Analyst 2021-11-9
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 2021-11-9
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.

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by