Skip to content

Digital-Image-Processing-kosta/Extract-dice-score-from-image

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EXTRACT DICE SCORE FROM IMAGE

Extracts the score from blue and red dices from a given image, also it outputs the score for each dice separately. Function 'extract_dice_score' returns 2 numbers that represent the sum of numbers on blue and red dices.
Function 'extract_dice_score_bonus' returns the score for each dice separately.

IMPLEMENTATION

Extraction of the scores on the blue and red dices:
The images are converted from RGB to HSV color format, because the idea is to use the saturation channel to extract blue and red dots from the background and to use hue channel to distinguish between red and blue dots. Setting the saturation threshold to 0.5 the image is binarized and the blue and red dots are extracted:
img1
To remove the blue and red dots on the sides, morphological operation of openning is performed. Then morphological operation of erosion is performed to separte the segments:
img2
By counting the connected objects on the resulting image the sum of the scores on the blue and red dices is extracted.
Setting the threshold for the hue channel to 0.93 red segments are extracted from the orignal image: img3
As before, same morphological operations of openning and erosion are applied:
img4
By counting the number of connected objects, the score of the red dices is calculated. Subtracting that score from the sum of the scores on the blue and red dices we get the score of the blue dices.

Extraction of the scores on each dice separately: Same segmentation steps are applied as before and now we have 2 binarized images. First image contains blue and red segments and the second contains only red segments. The following algorithm is applied on both images:
Using the function regionprops we extract the position of the centroids for each connected segment. Each centroid initially gets unique integer starting from 1. That number represents the number of the dice that centroid belongs to. We iterate thorugh all of the centroids and if the distance between 2 centroids is relatively small (threshold distance is hyperparameter), second centroid gets the integer number of the dice of the first centroid. Now resulting centroids that belong to the same dice have the same integer number. By summing the same integer numbers we get the score on each dice separately.
By applying this algorithm on the second image we get the scores of the red dices and by applying it to the first image we get scores of the red and blue dices. Excluding the scores which appear in the red dices from the joint scores we get the scores on the blue dices.

TEST:

Run the main.py to test the functions on 12 images.

NOTE:

Hyperparameters are tuned for Matlab 2017.

Releases

No releases published

Packages

No packages published

Languages