Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help writing MATLAB code that will detect and identify coins from the image below. Here's the code I have so far % Load
I need help writing MATLAB code that will detect and identify coins from the image below. Here's the code I have so far Load the image
imgPath C:UsersNezukoDownloadsIMGjpg;
img imreadimgPath;
figure; imshowimg; titleOriginal Image';
Convert to grayscale and enhance contrast
grayimg rgbgrayimg;
filteredimg medfiltgrayimg, ;
contrastimg adapthisteqfilteredimg;
figure; imshowcontrastimg; titleContrast Enhanced Image After Preprocessing';
Detect potential coin circles with optimized parameters
sensitivity ; Increased sensitivity for weaker edges
edgeThreshold ; Lower threshold to include more potential edges
centers radii, metric imfindcirclescontrastimg, 'ObjectPolarity', 'bright', 'Sensitivity', sensitivity 'EdgeThreshold', edgeThreshold;
figure; imshowcontrastimg; viscirclescenters radii, 'EdgeColor', b; titleDetected Circles Before Filtering';
Classify and label each detected coin based on its radius
knownpositions ; Store positions of identified coins
labels celllengthradii;
for i :lengthradii
if anypdistknownpositions, centersi: Check if this coin has been processed
continue;
end
Add position to known positions
knownpositions knownpositions; centersi:;
Coin classification based on radius
if radiii && radiii
labelsi 'Quarter';
elseif radiii && radiii
labelsi 'Nickel';
elseif radiii && radiii
labelsi 'Penny';
elseif radiii && radiii
labelsi 'Dime';
else
labelsi 'Unknown';
end
end
Display the final image with labels
figure; imshowimg;
hold on;
for i :sizecenters
if ~isemptylabelsi
textcentersi centersi labelsi 'Color', 'yellow', 'FontSize', 'FontWeight', 'bold', 'HorizontalAlignment', 'center', 'BackgroundColor', 'black';
viscirclescentersi: radiii 'EdgeColor', b;
end
end
titleFinal Image with Coin Classification and Labeling';
hold off;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started