MATLAB: Recognize black dot

Image Acquisition Toolboximage processingImage Processing Toolboximage segmentation

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!

Best Answer

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);