This was my internship project that is assigned to me. In this project I was challenged to not use any library or module for any process. Just by using C# System functions, I needed to detect both coins and determine which one has black dot on it.
So I've focused on developing two algorithms, one for detecting coins and the other for determining which coin has dot on it.
Checkout the project codebase from GitHub
First of all, I needed to detect coins. I did this using pixel similarity formula from the face similarity program that I've developed before. If pixel is similar with gray, pass that pixel, else set pixel as red (Image 1).
Note: In the next sections I implemented a method that scans image's specific percentage and determines background color to not use a single static color gray.
And that means I can tell the difference between coin and background. So I worked on algorithm that based on this.
First, I scanned image pixels vertically to find coin's width, then I scanned horizontally to detect height (Image 2-3-4-5-6).
Then I draw rectangles around coins using that coordinates (Image 7-8). That means I detected the coins and now I can extract them as two images and run a dot detection algorithm (Image 9).
So I implemented a simple dot detection algorithm that counts black pixels in image since I can use coins as 2 different images (Image 10).
Afterwards I draw ellipse on coin with dot (Image 11) and I added a settings section to not use any static variables in the program (Image 12-13).
My first project's method was easy to implement because I was using GetPixel() function. But in that method only way to traverse image pixels was using nested for loops because pixels was stored in 2D matrix. That limitation significantly slows the performance of the program.
So I developed a new algorithm that is based on byte arrays. In byte array, entire image is one dimensional array and that array contains image bytes. Each 3 sequence of bytes represents 1 pixel's RGB. [It has more details like image stride and etc.]
I developed an algorithm that slightly different from the first one because in byte array, I have one dimensional array. In the beginning I converted image to Black and White to separate background and coins (Image 1). Then I cleared up the black pixels in coin (Image 2). I did that using simple logic that searches for black sequence of pixels horizontally if there is no sequence, it converts that black pixel to white.
That was the most time consuming part for the program but it was necessary for finding width and height in next iterations because if we don't clean the black pixels in coin, we need to search for black sequence to determine if the coin ended or not for each byte. But if we clean the pixels then whenever we encounter black pixel, we can say that its the end of the coin (Image 3).
Then I started to develop an algorithm to find width and height (Image 4). It was not working well in the beginning because it has some bugs and logical mistakes (Image 5). But I kept improving the algorithm and finally implemented a solid algorithm that can detect coins and finds width, height and (x, y) coordinates for each coin (Image 6).
After detecting the coins its easy to determine which one has dot in it. I've cropped the coins from image using width and height coordinates. Then I scanned both image by traversing byte arrays. After counting the black pixels I was capable to determine the which coin has dot on it (Image 7).
Finally I've added a settings section (Image 8) to the program to not use static variables in project. Then I've added mouse-hover descriptions (Image 9) for each parameter to explain what are they used for. So any unfamiliar user can use this program which makes this program more user friendly.
There are no datasets linked
There are no datasets linked