How to count Azerbaijan copeck in matlab software ? (copeck -in Azerbaijan language Qepik)
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Vuqar Samedov
am 26 Dez. 2016
Bearbeitet: Vuqar Samedov
am 27 Dez. 2016
All are written on my copeck to 50 copecks. How do I solve this problem?
imageorj=imread('coins.jpg');
>> figure(1),imshow(imageorj);
>> %--------------------------------
>> image=rgb2gray(imageorj);
>> level=graythresh(image);
>> bw=im2bw(image,level);
>> figure(2),imshow(bw);
>> %------------------------------------------
>> bw=imcomplement(bw);
>> figure(3),imshow(bw)
>> bw=imfill(bw,'holes');
>> bw = bwareaopen(bw,30);
>> figure(4),imshow(bw);
>> %-----------------------------------------
>> se=strel('disk',11);
>> bw2=imerode(bw,se);
>> figure(5),imshow(bw2);
>> %-------------------------------------------
>> [B,L] = bwboundaries(bw2);
>> stats = regionprops(bw2, 'Area','Centroid');
>> figure(6),imshow(imageorj);
>> %------------------------------------------------
>> total = 0;
>> for n=1:length(B)
a=stats(n).Area;
centroid=stats(n).Centroid;
if a> 1200
total = total + 0.50;
text(centroid(1),centroid(2),'0.50 Qepik');
elseif a >800 && a < 1050
total = total + 0.20;
text(centroid(1),centroid(2),'20 Qepik');
elseif a >500 && a < 650
total = total + 0.10;
text(centroid(1),centroid(2),'10 Qepik');
elseif a > 360 && a < 380
total = total + 0.05;
text(centroid(1),centroid(2),'5 Qepik');
elseif a > 260 && a < 280
total = total + 0.03;
text(centroid(1),centroid(2),'3 Qepik');
else
total = total + 0.01;
text(centroid(1),centroid(2),'1 Qepik');
end
end
>> title(['Total coins amount = ',num2str(total),' AZN'])
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 26 Dez. 2016
You just had the areas wrong (and of course a bunch of other stuff that I've corrected). Fixed code is below.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
imageorj=imread('coins.jpg');
subplot(2, 3, 1);
imshow(imageorj);
drawnow;
axis on;
title('Original Image', 'FontSize', fontSize);
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
%--------------------------------
% Threshold
image=rgb2gray(imageorj);
level = graythresh(image);
bw = ~im2bw(image,level);
subplot(2, 3, 2);
imshow(bw);
title('Thresholded Image', 'FontSize', fontSize);
%------------------------------------------
% Fill holes.
bw=imfill(bw,'holes');
% Get rid of blobs less than 30 pixels big.
bw = bwareaopen(bw,30);
subplot(2, 3, 3);
imshow(bw);
title('Binary Image', 'FontSize', fontSize);
%-----------------------------------------
% Label the blobs
[labeledImage, numberOfCoins] = bwlabel(bw, 4);
subplot(2, 3, 4);
imshow(labeledImage, []);
title('Labeled Image', 'FontSize', fontSize);
%-------------------------------------------
stats = regionprops(labeledImage, 'Area', 'Centroid');
% Get areas and plot via bar chart.
allAreas = [stats.Area]
sortedAreas = sort(allAreas, 'descend')
subplot(2, 3, 5);
bar(sortedAreas, 'BarWidth', 1);
title('Areas', 'FontSize', fontSize);
grid on;
% Find the dividing lines of areas between different coin types.
d1 = (sortedAreas(5)+sortedAreas(6))/2
d2 = (sortedAreas(7)+sortedAreas(8))/2
d3 = (sortedAreas(9)+sortedAreas(10))/2
d4 = (sortedAreas(11)+sortedAreas(12))/2
d5 = (sortedAreas(13)+sortedAreas(14))/2
% Plot denominations over coins.
figure
imshow(imageorj);
%------------------------------------------------
total = 0;
coinFontSize = 15;
for n = 1 : numberOfCoins
thisArea = stats(n).Area
centroid = stats(n).Centroid;
if thisArea > 10158
total = total + 0.50;
caption = sprintf('50 Qepik, area = %d', thisArea);
elseif thisArea > 7561
total = total + 0.20;
caption = sprintf('20 Qepik, area = %d', thisArea);
elseif thisArea > 6605
total = total + 0.10;
caption = sprintf('10 Qepik, area = %d', thisArea);
elseif thisArea > 5317
total = total + 0.05;
caption = sprintf('5 Qepik, area = %d', thisArea);
elseif thisArea > 4518
total = total + 0.03;
caption = sprintf('3 Qepik, area = %d', thisArea);
else
total = total + 0.01;
caption = sprintf('1 Qepik, area = %d', thisArea);
end
text(centroid(1), centroid(2), caption, 'Color', 'b', 'FontSize', coinFontSize, 'FontWeight', 'bold');
end
% Display full screen.
caption = sprintf('Total coins amount = %.2f AZN', total);
title(caption, 'FontSize', fontSize)
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
helpdlg(caption);
2 Kommentare
Image Analyst
am 26 Dez. 2016
By the way, if you search for coins you'll see I've done this before http://www.mathworks.com/matlabcentral/answers/77721-counting-australian-coins-in-matlab
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Subplots finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!