How to identify black dots on dice via image processing? (MATLAB)

14 views (last 30 days)
Hi, I have some pictures of two white dices with black dots, and I need to recognize the value on each visible face of dices. For example, from this image:
I need to get [5 6]. Any ideas?
It's really urgent, I need to submit my final project and this is the last piece. Thanks a lot!

Answers (1)

Image Analyst
Image Analyst on 11 Oct 2015
It's not too hard. Of course it would be easier if you could start out with a good image. Why are you zoomed out so much and tossing the dice on a varying background? Why don't you toss them onto a dark background, like black velvet? This would reduce the chance you need to do any noise cleanup. If you're luck, you can just threshold for dark spots and call bwlabel() to count them
[!, numSpots] = bwlabel(grayImage < 128); % or whatever value works.
You can also adapt my Image Segmentation Tutorial for a full demo. Just reverse the direction of the < sign so that you threshold for dark spots instead of light spots. Here is the code:
If it fails for some images, then there are some things you can do, like first threshold for white (assuming that the only white will be on the dice), Then fill the holes with imfill() and then use this as a mask on the whole image. Then find the black spots.
Image Analyst
Image Analyst on 11 Oct 2015
Then first you'll need to identify each dice one at a time. First threshold for white and look for blobs of the right size. Then, if there is none but only a blob about twice as large, then the dice are touching and you'll have to split it apart with imerode. Then use your algorithm on each die one at a time.

Sign in to comment.


Find more on Image Processing and Computer Vision in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!