How to reduce valid coin mask true pixels outside valid coins?

6 views (last 30 days)
Hi, I need help for the valid coins segementation. I struggle to resolve the error: Your valid coin mask has one or more true pixels outside valid coins. I have try more than 30 attempts but still don't get to resolve the error. I don' t know where is my code went wrong. I even try many times to adjust the dilate and erode values and find circles values, but still not resolve the error.
[testcoinMask,MaskedtestCoin] = segmentCoinFace(testCoinImage);
se = strel("disk", 25, );
testcoinMask = imfill(testcoinMask, "holes");
testcoinMask = imerode(testcoinMask, se);
imgFilt = imgaussfilt(MaskedtestCoin, 1, "Padding", "circular","FiltterDomain,"Frequency","FilterSize",3);
faceEdgeMask = edge(imgFilt, "sobel", 0.04, "both");
faceEdgeMask(~testcoinMask) = false;
seFE = strel("disk",60,0);
fEdgeMask = imfill(faceEdgeMask, "holes");
BW2 = imdilate(fEdgeMask,seFE);
validCoinMask = BW2 & testcoinMask;
se2 = strel("disk",65,0);
validCoinMask = imdilate(validCoinMask, se2);
imshow(validCoinMask)
[centers,radii] = imfindcircles(validCoinMask,[105,150]);
imshow(validCoinMask);
viscircles(centers,radii,"Edgecolor','b');
coinProps = regionprops("table",validCoinMask,"Area","Perimeter","Centroid");
disp(coinProps)

Accepted Answer

Image Analyst
Image Analyst on 25 May 2023
Don't use imfindcircles. Use bwareafilt to select only a certain number of blobs, or blobs in a certain size range.
  5 Comments
Image Analyst
Image Analyst on 12 Jul 2023
@Ahsan please start your own new dicsussion thread and attach your "testCoinImage3.png" image and m-file with the paperclip icon. By the way, the call to imadjust is not needed and just slows it down.

Sign in to comment.

More Answers (0)

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!