Akhir-akhir ini sering muncul kasus di masyarakat tentang keamanan daging sapi dan kambing seperti pemalsuan daging sapi, daging kambing dipalsukan dengan daging babi oleh oknum-oknum tidak bertanggung jawab. Kondisi ini tentu saja dapat merugikan konsumen terutama konsumen di pasar tradisional dan mengingat banyaknya konsumen di kalangan masyarakat indonesia ini sebagian besar merupakan masyarakat muslim. Kurangnya pengetahuan masyarakat tentang cara membedakan daging sapi, daging kambing dengan daging babi menjadikan konsumen tidak teliti dalam membeli daging. Maka dari itu demi melindungi konsumen dari kasus penipuan seperti ini, perlu adanya suatu alat atau sistem yang dapat membantu masyarakat untuk mengenali daging sapi, daging kambing dan daging babi. Teknologi pengenalan pola saat ini telah banyak mengalami perkembangan. Hal ini dapat dimanfaatkan untuk membantu menyelesaikan masalah ini dengan membuat suatu sistem yang dapat mengklasifikasi jenis daging secara otomatis untuk mengurangi masalah-masalah tentang pemalsuan daging.
Berikut ini merupakan
contoh pemrograman matlab untuk melakukan ekstraksi ciri citra daging babi,
daging kambing, dan daging sapi menggunakan tekstur GLCM. Langkah-langkahnya
sebagai berikut:
1. Membaca citra RGB.
Citra Asli atau Citra RGB
2. Memotong Citra menjadi ukuran 2091.5 x
1371.5 x 978 x 852.
Cropping Citra
3. Resize ukuran citra
yang telah di potong dengan ukuran piksel menjadi 256 x 256, agar piksel
dari semua citra sama
Resize Citra
4. Mengkonversi Citra menjadi citra keabuan yang bertujuan untuk menuju tahap selanjutnya yaitu GLCM, karena GLCM hanya dapat diolah ketika citra sudah dalam bentuk citra keabuan.
Citra Grayscale
5. Mencari Nilai Gray-Level Co-Occurrence Matrix (GLCM), Ciri GLCM yang diekstrak adalah Angular Second Moments, Contrast, Correlation, Variance, Inverse Different Moment, dan Entropy.
GLCM
Source code yang digunakan adalah sebagai berikut:
seluruh citra daging
dapat didownload melalui:
https://mega.nz/folder/PqYynKZQ#_XI31flX_gNlKdlE0JoaSw
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | function CiriOrdeDua(Citra) clc, clear all, warning off all; tic; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Read Image % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% [fname,pname] = uigetfile({'*.jpg';'*.bmp';'*.png';'*.tif';'*.ppm';},'Open Image'); gambar = imread([pname fname]); figure (1); imwrite(gambar, 'Gambar Asli.jpg'); imshow(gambar); title('Gambar Asli'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Cropping Gambar % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% crop = imcrop(gambar,[2091.5 1371.5 978 852]); figure (2); imwrite(crop, 'Cropping Gambar.jpg'); imshow(crop); title('Cropping Gambar'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Resize Gambar % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% resize = imresize (crop,[256 256]); figure (3); imwrite(resize, 'Resize Citra.jpg'); imshow(resize); title('Resize Citra'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Grayscale Gambar % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% grayscale = rgb2gray(resize); %proses Grayscaling figure (4); imwrite(grayscale, 'Citra Keabuan.jpg'); imshow(grayscale); title('Citra Keabuan'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % GLCM % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Citra=grayscale; mk000=ko000(Citra); mk045=ko045(Citra); mk090=ko090(Citra); mk135=ko135(Citra); MatKook=(mk000+mk045+mk090+mk135)/4; I=[1:256]; SumX=sum(MatKook); SumY=sum(MatKook'); MeanX=SumX*I'; MeanY=SumY*I'; StdX=sqrt((I-MeanX).^2*SumX'); StdY=sqrt((I-MeanY).^2*SumY'); CiriASM=sum(sum(MatKook.^2)); CiriCON=0;CiriCOR=0;CiriVAR=0;CiriIDM=0;CiriENT=0; for i=1:256 for j=1:256 TempCON = (i-j)*(i-j)*MatKook(i,j); TempCOR = (i)*(j)*MatKook(i,j); TempVAR = (i-MeanX)*(j-MeanY)*MatKook(i,j); TempIDM = (MatKook(i,j))/(1+(i-j)*(i-j)); TempENT = -(MatKook(i,j))*(log2(MatKook(i,j)+eps)); CiriCON = CiriCON + TempCON; CiriCOR = CiriCOR + TempCOR; CiriVAR = CiriVAR + TempVAR; CiriIDM = CiriIDM + TempIDM; CiriENT = CiriENT + TempENT; end end CiriCOR=(CiriCOR-MeanX*MeanY)/(StdX*StdY); fprintf('\n\tANGULAR SECOND MOMENTS :%13.4f\n',CiriASM); fprintf('\n\tCONTRAST :%13.4f\n',CiriCON); fprintf('\n\tCORRELATION :%13.4f\n',CiriCOR); fprintf('\n\tVARIANCE :%13.4f\n',CiriVAR); fprintf('\n\tINVERS DIFFERENCE MATRIX :%13.4f\n',CiriIDM); fprintf('\n\tENTROPY :%13.4f\n',CiriENT); %ko000.m - MATRIKS KOOKURENSI ARAH 0 DERAJAT function MatriksHasil=ko000(GambarAsli) GambarAsli=double(GambarAsli); Temp=zeros(256); [tinggi,lebar]=size(GambarAsli); for i=1:tinggi for j=1:lebar-1 p=GambarAsli(i,j)+1; q=GambarAsli(i,j+1)+1; Temp(p,q) = Temp(p,q)+1 ; Temp(q,p) = Temp(q,p)+1 ; end end Jumlahpixel=sum(sum(Temp)); MatriksHasil=Temp/Jumlahpixel; %ko045.m - MATRIKS KOOKURENSI ARAH 45 DERAJAT function MatriksHasil=ko045(GambarAsli) GambarAsli=double(GambarAsli); Temp=zeros(256); [tinggi,lebar]=size(GambarAsli); for i=2:tinggi for j=1:lebar-1 p=GambarAsli(i,j)+1; q=GambarAsli(i-1,j+1)+1; Temp(p,q) = Temp(p,q)+1; Temp(q,p) = Temp(q,p)+1; end end Jumlahpixel=sum(sum(Temp)); MatriksHasil=Temp/Jumlahpixel; %ko090.m - MATRIKS KOOKURENSI ARAH 90 DERAJAT function MatriksHasil=ko090(GambarAsli) GambarAsli=double(GambarAsli); Temp=zeros(256); [tinggi,lebar]=size(GambarAsli); for i=2:tinggi for j=1:lebar p=GambarAsli(i,j)+1; q=GambarAsli(i-1,j)+1; Temp(p,q) = Temp(p,q)+1 ; Temp(q,p) = Temp(q,p)+1 ; end end Jumlahpixel=sum(sum(Temp)); MatriksHasil=Temp/Jumlahpixel; %ko135.m - MATRIKS KOOKURENSI ARAH 135 DERAJAT function MatriksHasil=ko135(GambarAsli) GambarAsli=double(GambarAsli); Temp=zeros(256); [tinggi,lebar]=size(GambarAsli); for i=2:tinggi for j=2:lebar p=GambarAsli(i,j)+1; q=GambarAsli(i-1,j-1)+1; Temp(p,q) = Temp(p,q)+1 ; Temp(q,p) = Temp(q,p)+1 ; end end Jumlahpixel=sum(sum(Temp)); MatriksHasil=Temp/Jumlahpixel; toc; |
0 Comments