What is the error at this demo program..?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Nimisha
il 16 Dic 2014
Commentato: Sean de Wolski
il 16 Dic 2014
clc;
close all;
imtool close all;
clear;
workspace;
format long g;
format compact;
fontSize = 20;
folder = 'C:\Users\admin\Desktop\matlab10questions';
baseFileName = 'Coins.jpg';
fullFileName = fullfile(folder, baseFileName);
grayImage = imread(fullFileName);
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
grayImage = grayImage(:, :, 2); % Take green channel.
end
[pixelCount, grayLevels] = imhist(grayImage);
binaryImage = grayImage < 240;
binaryImage = bwconvhull(binaryImage, 'objects', 4);
imshow(binaryImage);
binaryImage = bwareaopen(binaryImage, 2000);
[LabeledImage, numberOfCoins]=bwlabel(binaryImage);
measurements = regionprops(LabeledImage,'Area','Centroid');
allAreas = [measurements.Area];
total1=0;
total2=0;
total3=0;
total4=0;
hold on
for n=1:size(measurements,1);
centroid = measurements(n).Centroid;
X=centroid(1);
Y=centroid(2);
if measurements(n).Area < 40000;
text(X-10,Y,'$0.1')
total1=total1+1;
elseif 41000 < measurements(n).Area < 50000
total2=total2+2;
text(X-10,Y,'$0.25')
elseif 65000 < measurements(n).Area < 75000
total3=total3+3;
text(X-10,Y,'$1')
elseif 91000 < measurements(n).Area < 99000
total4=total4+3;
text(X-10,Y,'$0.5')
else
end
end
number = n
total1 = total1;
total2 = total2;
total3 = total3;
total4 = total4;
hold on
title(['Pennies: $',num2str(total1),' ','Nickels: $',num2str(total2),' ','Dimes: $',num2str(total3),' ','Quaters: $',num2str(total4), 'Number of coins:',num2str(n)],...
'FontSize', fontSize)
When i run this script it always shows only two values in image. for $0.1 and $0.25 only.
Why remaining values are not show.? All ranges are within limit and correct.
1 Commento
Image Analyst
il 16 Dic 2014
You forgot to attach your image so I can try your code with your image.
Risposta accettata
Image Analyst
il 16 Dic 2014
You can't do this kind of thing:
elseif 41000 < measurements(n).Area < 50000
You have to do it in two tests:
elseif (41000 < allAreas(n)) && (allAreas(n) < 50000)
1 Commento
Sean de Wolski
il 16 Dic 2014
Actually you can, it just returns unexpected results.
Più risposte (0)
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!