Is it possible to count the bolts in this image?
4 views (last 30 days)
Show older comments
Hello,
I've been practicing my segmentation on a number of different challenges, this one I've been having a lot of problems with and was hoping I could get a pointer in the right direction. I'm confident it's fairly simple, my methods are just the wrong ones.
Any help is greatly appreciated!
2 Comments
androidguy
on 29 Mar 2017
Try this?
clear variables
clc
close all
warning off
I1 = imread('screws.png');
figure, imshow(I1), title('original image');
I = rgb2gray(I1);
figure, imshow(I), title('original image');
[~, threshold] = edge(I, 'sobel');
fudgeFactor = .8;
BWs = edge(I,'sobel', threshold * fudgeFactor);
figure, imshow(BWs), title('binary gradient mask');
se90 = strel('line', 3, 90);
se0 = strel('line', 3, 0);
BWsdil = imdilate(BWs, [se90 se0]);
figure, imshow(BWsdil), title('dilated gradient mask');
BWdfill = imfill(BWsdil, 'holes');
figure, imshow(BWdfill);
title('binary image with filled holes');
BWnobord = imclearborder(BWdfill, 4);
figure, imshow(BWnobord), title('cleared border image');
seD = strel('diamond',1);
BWfinal = imerode(BWnobord,seD);
BWfinal = imerode(BWfinal,seD);
figure, imshow(BWfinal), title('segmented image');
BWoutline = bwperim(BWfinal);
Segout = I;
Segout(BWoutline) = 255;
figure, imshow(Segout), title('outlined original image');
Answers (0)
See Also
Categories
Find more on Image Filtering and Enhancement in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!