recognize black dot

15 views (last 30 days)
Ignazioc calo
Ignazioc calo on 19 Jun 2011
Commented: Image Analyst on 3 Oct 2015
Hi, i' m a college student, and i need your help. I have some images of white dices (with black points) on red background and i need to recognize the value on visible face of dices. I tried to convert image on black-white but the result is really wrong...can someone recommend some links about those problems?
thanks!

Accepted Answer

Image Analyst
Image Analyst on 19 Jun 2011
Well now that you posted an image, and I see you have black spots not only on the dice but also on the red background, I need to modify my answer to have you threshold on the blue or green channel:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
folder = 'C:\Documents and Settings\user\My Documents\Temporary stuff';
% Read in a color demo image.
baseFileName = 'IMG_0584.JPG';
fullFileName = fullfile(folder, baseFileName);
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows columns numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage, []);
title('Original color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
spots = blueChannel < 128;
subplot(2, 2, 2);
imshow(spots, []);
title('Thresholded Blue Channel', 'FontSize', fontSize);
spots = imclearborder(spots);
subplot(2, 2, 3);
imshow(spots, []);
title('Border Cleared', 'FontSize', fontSize);
% Fill holes
spots = imfill(spots, 'holes');
subplot(2, 2, 4);
imshow(spots, []);
title('Final Spots Image', 'FontSize', fontSize);
% Count them
[labeledImage numberOfSpots] = bwlabel(spots);
message = sprintf('Done!\nThe number of spots (total on both dice) is %d', numberOfSpots);
msgbox(message);
  6 Comments
Sapir
Sapir on 3 Oct 2015
I realize it's very old, but worth a shot. I'm using your algorithm to identify dots on two dice, but I'm struggling to identify how many dots in each dice. Any advice?
Image Analyst
Image Analyst on 3 Oct 2015
Advice is to post your image and code in a new question.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 19 Jun 2011
You are not clear about what "the result is really wrong" means ?
Threshold your image based upon either the blue or green channels. bwlabel() the image. regionprops() and look at the hole count of each region: it will be the number of dots (unless the shadows are fairly deep.)
  9 Comments
Walter Roberson
Walter Roberson on 19 Jun 2011
Indeed, the sample pictures do turn out to have two dice -- and a number of black spots on the red background. The algorithm I suggest would not have any difficulty with the black spots on the background.
Walter Roberson
Walter Roberson on 19 Jun 2011
EulerNumber is the regionprops() value you want. It will be 0 or negative, being one (1) object minus the number of holes (dots).
Depending on how distinct the dots are and whether there is any significant noise, it is possible that you might need to use imdilate() to fill in speckles or trim irregular shadows.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!