How can measure distance after threshold
3 views (last 30 days)
Show older comments
Hello,
how can measure the disance (x , y) after threshold (x, y) between the edge of image and the white region.
2 Comments
Accepted Answer
Image Analyst
on 14 Jul 2023
"the distance from the right side to any white region , and from botton to the any white region. "
To find the distance from the right side of the image to any white pixel, you can get that by scanning the image line by line
[rows, columns] = size(binaryImage);
rightEdges = zeros(rows, 1);
for row = 1 : rows
t = find(binaryImage(row, :), 1, 'last');
if ~isempty(t)
rightEdges(row) = t;
end
end
% Similarly to find the last row in each column, scan column-by-column:
bottomEdges = zeros(1, columns);
for col = 1 : columns
t = find(binaryImage(:, col), 1, 'last');
if ~isempty(t)
bottomEdges(col) = t;
end
end
% Find the closest pixel to the right edge of the image
[rightDistance, closestRow] = min(rightEdges)
% Find the closest pixel to the bottom edge of the image
[bottomDistance, closestCol] = min(bottomEdges)
1 Comment
Walter Roberson
on 14 Jul 2023
By the way, the algorithm I posted in my Answer is a vectorized way of finding the last set pixel
More Answers (2)
Walter Roberson
on 14 Jul 2023
First trim the white border off of the image. Then binarize and take the inverse of the image, so that the black become 1 and the white become 0. Then flipud() and fliplr() the inverse.
Now
vert_profile = fliplr(sum(cumprod(FlippedInverse,1),1));
horz_profile2 = flipud(sum(cumprod(FlippedInverse,2),2));
For any given column K of the cropped image, vert_profile(K) is the number of black rows at the bottom of the image (possibly 0). For any given row K of the cropped image, horz_profile(K) is the number of black columns at the right side of the image (possibly 0)
0 Comments
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!