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!