recognize black dot

23 ビュー (過去 30 日間)
Ignazioc calo
Ignazioc calo 2011 年 6 月 19 日
コメント済み: Image Analyst 2015 年 10 月 3 日
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!

採用された回答

Image Analyst
Image Analyst 2011 年 6 月 19 日
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 件のコメント
Sapir
Sapir 2015 年 10 月 3 日
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 2015 年 10 月 3 日
Advice is to post your image and code in a new question.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 6 月 19 日
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 件のコメント
Walter Roberson
Walter Roberson 2011 年 6 月 19 日
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 2011 年 6 月 19 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by