Betül SARAL

Bilgisayar Mühendisi

Matlab - Bozuk Para Sayma

| Comments

Matlab kullanarak aşağıdaki resimde ne kadar bozuk paramız var onu bulmaya çalışalım.

Programımız aşağıdaki gibidir.

test.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
	img = imread('image3.jpg');
    th = graythresh(img);
    bw = imcomplement(im2bw(img,th));  %gri seviyeli resimlerde negatiflik alir
    bw = bwareaopen(bw,30);  % 30pixelden kucuk olanlar kaldiriliyor.
    bw = imfill(bw,'holes');
    SE =strel('disk', 50);    % birlesik madeni paralarin ayrilmasi saglaniyor.
    bw2 = imerode(bw,SE);
    [L,num] = bwlabel(bw2);  % num ile para adetini ogrendik ve etiket atadik
    stats = regionprops(bw2, 'Area');

    count = 0;
    for n=1:num
        a = stats(n).Area;  % her paranın alanını öğrendik. Boyutlara göre hesaplama yaptık.
        switch logical(true)
            case a> 35000
                 count = count + 1;
            case a >25000  &&  a < 35000
                count = count + 0.5;
            case a >15000 &&  a < 20000
                count = count + 0.25;
            case a > 11000 &&  a < 13000
                count = count + 0.10;
            otherwise
                 count = count + 0.05;
        end
    end

   subplot(1,3,1), imshow(img)
   title(['Toplam para miktari = ',num2str(count),' TL'])
   subplot(1,3,2), imshow(bw)
   subplot(1,3,3), imshow(bw2)

Program çıktımız :

Comments