clc;
clear all;
close all;
Amount = 0;
Coins = imread('Coins4.jpeg');
CoinsBinary = im2bw(Coins,0.15);
se = strel('disk',20);
open=imopen(CoinsBinary,se);
fill = imfill(open,'holes');
clearing = imclearborder(fill);
figure
imshow(clearing)
diameter = regionprops(clearing,'MinorAxisLength');
A_cell = struct2cell(diameter);
for j = 1:length(diameter)
r(j) = A_cell{j};
end
radius =r/2;
rMin = int32(min(radius));
rMax = int32(max(radius));
[centers, radii] = imfindcircles(clearing,[rMin rMax],'ObjectPolarity','bright','Sensitivity',0.98,'EdgeThreshold',0.85);
numCircles = length(centers)
figure
imshow(Coins)
h = viscircles(centers,radii);
for i = 1:numCircles
if radii(i) > rMin && radii(i) < 140
Amount = Amount + 0.1;
elseif radii(i) > 140 && radii(i) < 150
Amount = Amount + 0.2;
elseif radii(i) > 150 && radii(i) < 160
Amount = Amount + 1;
elseif radii(i) > 160 && radii(i) < 170
Amount = Amount + 0.5;
elseif radii(i) > 170 && radii(i) < rMax
Amount = Amount + 2;
end
end
fprintf('Total amount of coins: %.2f €', Amount);