필터 지우기
필터 지우기

What is the error at this demo program..?

조회 수: 1 (최근 30일)
Nimisha
Nimisha 2014년 12월 16일
댓글: Sean de Wolski 2014년 12월 16일
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
Image Analyst
Image Analyst 2014년 12월 16일
You forgot to attach your image so I can try your code with your image.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2014년 12월 16일
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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by