Showing the error “Variable nDimes has an incorrect value”
For this problem your code will need to do the following:
Accurately determine the number of each coin type present. Use variable names nDimes, nNickels, nQuarters, and nFiftyCents.
Calculate the total $ value of coins present. Use variable name USD
The code:
testImageIdx = randi([1,3]);
testCoinImage = imread("testCoinImage" + testImageIdx + ".png");
imshow(testCoinImage);
title("Original Coin Image");
[testcoinMask, MaskedtestCoin] = segmentCoin(testCoinImage);
se = strel(‘disk’, 20, 0);
testCoinMask = imfill(testcoinMask, ‘holes’);
testCoinMask = imerode(testcoinMask, se);
imgFilt = imgaussfilt(MaskedtestCoin, 0.5, ‘Padding’, "circular", ‘FilterDomain’, "frequency", ‘FilterSize’, 3);
faceEdgeMask = edge(imgFilt, "sobel", 0.05, "both");
faceEdgeMask(~testcoinMask) = false;
imshow(faceEdgeMask);
title("Edge Mask Detection for Valid Coins");
see = strel("disk", 25, 0);
fb = imfill(faceEdgeMask, "holes");
Bw2 = imdilate(fb, see);
validCoinMask = Bw2 & testcoinMask;
set = strel("disk", 2, 0);
validCoinMask = imdilate(validCoinMask, set);
montage({testcoinMask, validCoinMask});
title("testcoinMask vs ValidCoinMask");
coinSizes = regionprops("table", validCoinMask, "Area");
nDimes = coinSizes.Area < 1100;
nDimes = sum(nDimes);
nNickels = (coinSizes.Area > 1100 & coinSizes.Area < 2200);
nNickels = sum(nNickels);
nQuarters = (coinSizes.Area > 2200 & coinSizes.Area < 3200);
nQuarters = sum(nQuarters);
nFiftyCents = coinSizes.Area >= 3200;
nFiftyCents = sum(nFiftyCents);
USD = (nDimes * 0.10) + (nNickels * 0.05) + (nQuarters * 0.25) + (nFiftyCents * 0.50);
function [testcoinMask, MaskedtestCoin] = segmentCoin(X)
X = im2gray(X);
testcoinMask = im2gray(X) > 150;
radius = 12;
decomp = 4;
se = strel(‘disk’, radius, decomp);
testcoinMask = imclose(testcoinMask, se);
MaskedtestCoin = X;
MaskedtestCoin(~testcoinMask) = 0;
endFor this problem your code will need to do the following:
Accurately determine the number of each coin type present. Use variable names nDimes, nNickels, nQuarters, and nFiftyCents.
Calculate the total $ value of coins present. Use variable name USD
The code:
testImageIdx = randi([1,3]);
testCoinImage = imread("testCoinImage" + testImageIdx + ".png");
imshow(testCoinImage);
title("Original Coin Image");
[testcoinMask, MaskedtestCoin] = segmentCoin(testCoinImage);
se = strel(‘disk’, 20, 0);
testCoinMask = imfill(testcoinMask, ‘holes’);
testCoinMask = imerode(testcoinMask, se);
imgFilt = imgaussfilt(MaskedtestCoin, 0.5, ‘Padding’, "circular", ‘FilterDomain’, "frequency", ‘FilterSize’, 3);
faceEdgeMask = edge(imgFilt, "sobel", 0.05, "both");
faceEdgeMask(~testcoinMask) = false;
imshow(faceEdgeMask);
title("Edge Mask Detection for Valid Coins");
see = strel("disk", 25, 0);
fb = imfill(faceEdgeMask, "holes");
Bw2 = imdilate(fb, see);
validCoinMask = Bw2 & testcoinMask;
set = strel("disk", 2, 0);
validCoinMask = imdilate(validCoinMask, set);
montage({testcoinMask, validCoinMask});
title("testcoinMask vs ValidCoinMask");
coinSizes = regionprops("table", validCoinMask, "Area");
nDimes = coinSizes.Area < 1100;
nDimes = sum(nDimes);
nNickels = (coinSizes.Area > 1100 & coinSizes.Area < 2200);
nNickels = sum(nNickels);
nQuarters = (coinSizes.Area > 2200 & coinSizes.Area < 3200);
nQuarters = sum(nQuarters);
nFiftyCents = coinSizes.Area >= 3200;
nFiftyCents = sum(nFiftyCents);
USD = (nDimes * 0.10) + (nNickels * 0.05) + (nQuarters * 0.25) + (nFiftyCents * 0.50);
function [testcoinMask, MaskedtestCoin] = segmentCoin(X)
X = im2gray(X);
testcoinMask = im2gray(X) > 150;
radius = 12;
decomp = 4;
se = strel(‘disk’, radius, decomp);
testcoinMask = imclose(testcoinMask, se);
MaskedtestCoin = X;
MaskedtestCoin(~testcoinMask) = 0;
end For this problem your code will need to do the following:
Accurately determine the number of each coin type present. Use variable names nDimes, nNickels, nQuarters, and nFiftyCents.
Calculate the total $ value of coins present. Use variable name USD
The code:
testImageIdx = randi([1,3]);
testCoinImage = imread("testCoinImage" + testImageIdx + ".png");
imshow(testCoinImage);
title("Original Coin Image");
[testcoinMask, MaskedtestCoin] = segmentCoin(testCoinImage);
se = strel(‘disk’, 20, 0);
testCoinMask = imfill(testcoinMask, ‘holes’);
testCoinMask = imerode(testcoinMask, se);
imgFilt = imgaussfilt(MaskedtestCoin, 0.5, ‘Padding’, "circular", ‘FilterDomain’, "frequency", ‘FilterSize’, 3);
faceEdgeMask = edge(imgFilt, "sobel", 0.05, "both");
faceEdgeMask(~testcoinMask) = false;
imshow(faceEdgeMask);
title("Edge Mask Detection for Valid Coins");
see = strel("disk", 25, 0);
fb = imfill(faceEdgeMask, "holes");
Bw2 = imdilate(fb, see);
validCoinMask = Bw2 & testcoinMask;
set = strel("disk", 2, 0);
validCoinMask = imdilate(validCoinMask, set);
montage({testcoinMask, validCoinMask});
title("testcoinMask vs ValidCoinMask");
coinSizes = regionprops("table", validCoinMask, "Area");
nDimes = coinSizes.Area < 1100;
nDimes = sum(nDimes);
nNickels = (coinSizes.Area > 1100 & coinSizes.Area < 2200);
nNickels = sum(nNickels);
nQuarters = (coinSizes.Area > 2200 & coinSizes.Area < 3200);
nQuarters = sum(nQuarters);
nFiftyCents = coinSizes.Area >= 3200;
nFiftyCents = sum(nFiftyCents);
USD = (nDimes * 0.10) + (nNickels * 0.05) + (nQuarters * 0.25) + (nFiftyCents * 0.50);
function [testcoinMask, MaskedtestCoin] = segmentCoin(X)
X = im2gray(X);
testcoinMask = im2gray(X) > 150;
radius = 12;
decomp = 4;
se = strel(‘disk’, radius, decomp);
testcoinMask = imclose(testcoinMask, se);
MaskedtestCoin = X;
MaskedtestCoin(~testcoinMask) = 0;
end image processing, image segmentation, image analysis MATLAB Answers — New Questions