Question: testImageIdx = randi ( [ 1 , 3 ] ) testCoinImage = imread ( testCoinImage + testImageIdx + . png )

testImageIdx = randi([1,3])
testCoinImage = imread("testCoinImage"+testImageIdx+".png");
title("Original Coin Image");
[testcoinMask,MaskedtestCoin]= segmentCoin(testCoinImage);
% Shrink the coin mask.
se = strel('disk',20,0);
testcoinMask = imfill(testcoinMask, 'holes'); % Fill any holes in it.
testcoinMask = imerode(testcoinMask, se); % Shrink by 3 layers of pixels.
% Find edges using original poster's code.
imgFilt = imgaussfilt(MaskedtestCoin,0.5,...
Padding="circular",FilterDomain="frequency",FilterSize=3);
faceEdgeMask = edge(imgFilt,"sobel",0.05,"both");
% Erase outside the shrunken coin mask to get rid of outer boundary.
faceEdgeMask(~testcoinMask)= false;
imshow(faceEdgeMask);
title("Edge Mask Detection for Valid Coins")
se = strel('disk',5); % You can adjust the disk size based on your requirements
dilatedFaceEdgeMask = imdilate(faceEdgeMask, se);
% Step 5: Logical combination of dilated face edge mask and foreground mask
validCoinMask = dilatedFaceEdgeMask & testcoinMask;
% Step 6: Display the original image, testCoinMask, faceEdgeMask, and validCoinMask
figure;
subplot(2,2,1); imshow(testCoinImage); title('Original Image');
subplot(2,2,2); imshow(testcoinMask); title('Foreground Mask');
subplot(2,2,3); imshow(faceEdgeMask); title('Face Edge Mask');
subplot(2,2,4); imshow(validCoinMask); title('Valid Coin Mask');
% Step 7: Save the validCoinMask for further analysis or evaluation
save("validCoinMask.mat", "validCoinMask");
function [testcoinMask,MaskedtestCoin]= segmentCoin(X)
%segmentImage Segment image using auto-generated code from Image Segmenter app
%[BW,MASKEDIMAGE]= segmentImage(X) segments image X using auto-generated
% code from the Image Segmenter app. The final segmentation is returned in
% BW, and a masked image is returned in MASKEDIMAGE.
% Auto-generated by imageSegmenter app on 31-Dec-2022
%----------------------------------------------------
X = im2gray(X);
% Threshold image - manual threshold
testcoinMask = im2gray(X)>150;
% Close mask with default
radius =12;
decomposition =4;
se = strel('disk', radius, decomposition);
testcoinMask = imclose(testcoinMask, se);
% Create masked image.
MaskedtestCoin = X;
MaskedtestCoin(~testcoinMask)=0;
end
this is my code for the valid coin segmentations
testImageIdx =
2
Figure 2 of 2
the error imgetting is :
Assessment result: incorrectIs the valid coin mask correct?
Your coin mask is not capturing the full area of all valid coins.
 testImageIdx = randi([1,3]) testCoinImage = imread("testCoinImage"+testImageIdx+".png"); title("Original Coin Image"); [testcoinMask,MaskedtestCoin]= segmentCoin(testCoinImage);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!