Answered step by step
Verified Expert Solution
Link Copied!

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:\Users\Nezuko\Downloads\IMG_4541.jpg';
img = imread(imgPath);
figure; imshow(img); title('Original Image');
% Convert to grayscale and enhance contrast
gray_img = rgb2gray(img);
filtered_img = medfilt2(gray_img, [33]);
contrast_img = adapthisteq(filtered_img);
figure; imshow(contrast_img); title('Contrast Enhanced Image After Preprocessing');
% Detect potential coin circles with optimized parameters
sensitivity =0.95; % Increased sensitivity for weaker edges
edgeThreshold =0.01; % Lower threshold to include more potential edges
[centers, radii, metric]= imfindcircles(contrast_img, [1832], 'ObjectPolarity', 'bright', 'Sensitivity', sensitivity, 'EdgeThreshold', edgeThreshold);
figure; imshow(contrast_img); viscircles(centers, radii, 'EdgeColor', 'b'); title('Detected Circles Before Filtering');
% Classify and label each detected coin based on its radius
known_positions =[]; % Store positions of identified coins
labels = cell(length(radii),1);
for i =1:length(radii)
if any(pdist2(known_positions, centers(i,:))10)% Check if this coin has been processed
continue;
end
% Add position to known positions
known_positions =[known_positions; centers(i,:)];
% Coin classification based on radius
if radii(i)>=26 && radii(i)=32
labels{i}= 'Quarter';
elseif radii(i)>=23 && radii(i)=25
labels{i}= 'Nickel';
elseif radii(i)>=19 && radii(i)=22
labels{i}= 'Penny';
elseif radii(i)>=18 && radii(i)=18
labels{i}= 'Dime';
else
labels{i}= 'Unknown';
end
end
% Display the final image with labels
figure; imshow(img);
hold on;
for i =1:size(centers,1)
if ~isempty(labels{i})
text(centers(i,1), centers(i,2), labels{i}, 'Color', 'yellow', 'FontSize', 12, 'FontWeight', 'bold', 'HorizontalAlignment', 'center', 'BackgroundColor', 'black');
viscircles(centers(i,:), radii(i), 'EdgeColor', 'b');
end
end
title('Final Image with Coin Classification and Labeling');
hold off;
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

Students also viewed these Databases questions

Question

3 What are the aims of appraisal?

Answered: 1 week ago

Question

7 Compare and contrast evaluative and developmental appraisal.

Answered: 1 week ago