Coin Value Recognition from Images
Contents
I. Problem Statement 2
II. Implement 2
Stage 1: Converting coin images from RGB to Gray Image (Binary Image) 3
Stage 2: Spliting the edge of images 3
Stage 3: Making the coins into complete white circle. 4
Stage 4: Distinguishing circle 5
Stage 5: Determine diameter of each circle 7
Stage 6: Comparing and show result 7
III. Result 7
IV. Limitation and Future Plan 8
V. Code 8
Report Coin Value Recognition from Images Instructor: Nguyễn Việt Dũng Student: Nguyễn Trung Hiếu, Trần Trung Hoàn Class: BME K54 Contents Problem Statement Nowadays in Vietnam, coin still is allowed circulated. Coins can be used in some public telephones and automatic selling machine. In these machine, we give some coins into a holes and this machine will detect what value we gave. In this project, I will design a program which can detect coin value in image. This program is coded by Matlab. There are 5 par values of coin, 200, 500, 1000, 2000 and 5000. Each of coin values has different colors and sizes. So if we can calculate diameter of coin in images, we will determine value of that coin. In this Project, I use a smartphone camera with 0.3M resolution to capture coin images. Original image has size of 640 x 480. But in Matlab, the image with this size is too big to fit on screen. So I cut down size of image into 450 x 330. Size of coin in image depend on distance from camera to coin. With distance is 10 cm, relative size of each coin is: Value Real diameter Number of pixels in images 200 20 mm 57 – 62 500 22 mm 62 – 67 1000 19 mm 54 – 57 2000 23.5 mm 67 – 71 5000 25.5 mm 71 – 76 With the distance is 22 cm, relative size of each coin is: Value Number of pixels in images 200 26 – 28 500 28 – 30 1000 24 – 26 2000 30 – 32 5000 32 – 35 From 2 above table, if we choose small distance, the difference of coin values is bigger and easier to detect. So I choose distance from camera to coin is 10 cm. Implement In this part, I use an image captured by smartphone camera same part I. Type of image is jpeg. In this image, there are 5 Vietnam coins having different value. Stage 1: Converting coin images from RGB to Gray Image (Binary Image) Because images from smartphone camera is RGB images, so to process in Matlab, we must convert it into grayscale images by using rgb2gray function. I = rgb2gray(I); Stage 2: Spliting the edge of images From pixels brightness changes abruptly, we can find the edge of images by using Edge Detection function with Canny method. For Canny method, the Edge Detection block finds edges by looking for the local maxima of the gradient of the input image. Here, we choose threshold is 0.3 c = edge(I, ‘canny’, 0.3); Because image is quite bright , so when we have removed edge, there are the black spots inside the coins: Stage 3: Making the coins into complete white circle. In this stage, we will remove entirely black spots inside the coin by using strel function. strel can create a structuring element with shape. Here, we use shape ‘disk’ for coin images. After that, we dilate above images. With function “imdilate”, we can dilate grayscale image and returning the dilated image. se = strel(‘disk’, 2); I2 = imdilate(c, se); The argument “se” is structuring element object returned by the strel function. Next, we use imfill function to fill holes in the binary image. A hole is a set of background pixels that can cannot be reached by filling in the background from the edge of the image. d2 = imfill(I2, ‘holes’); Stage 4: Distinguishing circle To distringuish circles, we must number them by using bwlabel function. label = bwlabel(d2,4) This function returns a matrix Label, of the same size as d2, containing labels for the connected objects in d2. Here, we use 1 connected objects. After that, we set each circle in each matrix. How many there are circles, there are same numbers of matrix. a1 = (label ==1); a2 = (label == 2); a3 = (label == 3); a4 = (label == 4); a5 = (label == 5); Stage 5: Determine diameter of each circle Because each of coin value has different diameter, so to determine value of coin 200 500 1000 2000 5000, we calculate diameter of each circle by use Euclidean transform. k = bwdist(~m); It will compute the Euclidean distance transform of the binary image m. For each pixel in m, the distance transform assigns a number that is the distance between that pixel and the nearest nonzero pixel of m. bwdist uses the Euclidean distance metric by default. Maximum distance in this transform is diameter of circle. dia = max(max(k)); Stage 6: Comparing and show result From diameter of each circle calculated, we compare with relative diameter of each coin value in part I. If it is satisfy, we can conclude value of each coin in images. T = [1000 200 500 2000 5000]; String = ‘Figure %d has value % dong \n’; Notstring = ‘This figure is not Vietnam coin’ \n; fprintf(‘diameter of coin is: %f ‘, dia); If (56<dia) & (dia<59) fprint(string, n, T(1)) elseif (59<dia) & (dia<62) fprintf(string,n,T(2)) elseif (62<dia) & (dia<67) fprintf(string,n,T(3)) elseif (67<dia) & (dia<71) fprintf(string,n,T(4)) elseif (71<dia) & (dia<76) fprintf(string,n,T(5)) Result After running program, we have result: This result show exactly value of coins in the image. Limitation and Future Plan Although result of program is exactly, this program has some limitation: The diameter of coins in images is not precisely, depend on quality of camera and distance between coin and camera This program is not auto determine how many there are coins in images. Because of limited time, the program is not complete. In the future, I will design a GUI interface with more options to implement program. Code This is Matlab code of our program: fprintf('Project: DIGITAL IMAGING PROCESSING \nStudent : Nguyen Trung Hieu, Tran Trung Hoan \nInstructor: Nguyen Viet Dung \n') fprintf('\nTopic: Coin Value Recognition from Images \n') file = input('\n Input file name of image :','s'); %input name of coin image I = imread(file); %read image file I=rgb2gray(I);% convert RGB image to gray image figure;imshow(I);%show gray image c = edge(I, 'canny',0.3); % Split edge of image, threshold selection is 0.3 figure; imshow(c); se = strel('disk',2); %remove entirely black spots inside the coinremove entirely black spots inside the coin I2 = imdilate(c,se); %dilate grayscale image imshow(I2); d2 = imfill(I2, 'holes'); % fill holes in the binary image figure, imshow(d2); Label=bwlabel(d2,4); %number of ech circle in image % set each circle in each matrix a1=(Label==1); a2=(Label==2); a3=(Label==3); a4=(Label==4); a5=(Label==5); T=[1000 200 500 2000 5000]; string='Figure %d has value %d dong \n'; notstring='This figure is not Vietnam coin! \n'; disp('In order of figure displaying, value of coin in image is: ') for n = 1:5 if (n==1) m=a1; elseif (n==2) m=a2; elseif (n==3) m=a3; elseif (n==4) m=a4; else m=a5; end k= bwdist(~m); % determine Euclidean distance to nearest nonzero pixel figure, imshow(k,[]), % Display each figure by min max threshold of matrix m dia=max(max(k)); % diameter of circle is maximum Euclidean distance fprintf('Diameter of circle is: %f \n', dia); % Determine coin values if (55 < dia) & (dia < 58) fprintf(string,n,T(1)) % t1=T(1); elseif (58 < dia) & (dia < 62) fprintf(string,n,T(2)) % t2=T(2); elseif (62 < dia) & (dia < 67) fprintf(string,n,T(3)) %t3=T(3); elseif (67 < dia) & (dia < 71) fprintf(string,n,T(4)) % t4=T(4); elseif (71 < dia) & (dia < 76) fprintf(string,n,T(5)) else fprintf(notstring) end end
File đính kèm:
- coin_value_recognition_from_images.docx
- Report Medical Image Processing.pdf