How can measure distance after threshold
4 次查看(过去 30 天)
显示 更早的评论
Hello,
how can measure the disance (x , y) after threshold (x, y) between the edge of image and the white region.
2 个评论
采纳的回答
Image Analyst
2023-7-14
"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 个评论
Walter Roberson
2023-7-14
By the way, the algorithm I posted in my Answer is a vectorized way of finding the last set pixel
更多回答(2 个)
Walter Roberson
2023-7-14
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!