Count lines in an Image

3 次查看(过去 30 天)
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

采纳的回答

sloppydisk
sloppydisk 2018-4-30
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

更多回答(1 个)

sloppydisk
sloppydisk 2018-4-30
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!

Translated by