Count lines in an Image
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Oreoluwa ADESINA
il 30 Apr 2018
Commentato: Walter Roberson
il 13 Mag 2018
Hi, I would really appreciate some urgent help with this question, Im trying to count lines in a binary image using "bwboundries" but I only want to count particular lines which fall in between a size/length range so as to avoid counting blobs that are not lines. I have attached an image for more clarity. From the image I have horizontal and vertical ones I want to count, but some are just blobs and my current code includes the blobs in the total count, i would like to eliminate that. Thanks for the help
Risposta accettata
sloppydisk
il 30 Apr 2018
I adapted some code from the example OverlayRegionBoundariesOnImageExample.mlx to do what you probably want
% Overlay Region Boundaries on Image
% Read grayscale image into the workspace.
I = imread('myImg.png');
% Convert grayscale image to binary image using local adaptive thresholding.
BW = imbinarize(I);
% Calculate boundaries of regions in image and overlay the boundaries on the image.
[B,L] = bwboundaries(BW,'noholes');
% Create function handle for diagonal length
hypotFun = @(x) hypot(max(x(:, 1)) - min(x(:, 1)), max(x(:, 2)) - min(x(:, 2)));
% Set minimum length
minimumLength = 10;
% Logical indexing for allowable length
check = cellfun(hypotFun, B) > minimumLength;
Bnew = B(check);
hold on
% Plot
for k = 1:length(Bnew)
boundary = Bnew{k};
plot(boundary(:,2), boundary(:,1), 'b', 'LineWidth', 2)
end
0 Commenti
Più risposte (1)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!