How can measure distance after threshold
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
weam
le 13 Juil 2023
Commenté : Walter Roberson
le 14 Juil 2023
Hello,
how can measure the disance (x , y) after threshold (x, y) between the edge of image and the white region.
2 commentaires
Réponse acceptée
Image Analyst
le 14 Juil 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 commentaire
Walter Roberson
le 14 Juil 2023
By the way, the algorithm I posted in my Answer is a vectorized way of finding the last set pixel
Plus de réponses (2)
Walter Roberson
le 14 Juil 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 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!