Clear Filters
Clear Filters

Count lines in an Image

3 views (last 30 days)
Oreoluwa ADESINA
Oreoluwa ADESINA on 30 Apr 2018
Commented: Walter Roberson on 13 May 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

Accepted Answer

sloppydisk
sloppydisk on 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

More Answers (1)

sloppydisk
sloppydisk on 30 Apr 2018
Is it just me or did you not attach any image?

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!