how to separate two dice images via matlab
5 views (last 30 days)
Show older comments
Hi, I'm using "Image Analyst"'s algorithm to identify black dots on two dice. I need to detect exactly how many dots on each dice. Any suggestions?
Attached the algorithm and the image.
code:
=======
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.
% Read in a color demo image.
cam = webcam(2);
set(cam, 'Brightness', 150);
set(cam, 'Saturation', 110);
pos = [93.5 175.5 452 113];
rgb = snapshot(cam);
%work - [295.5 224.5 23 38]
X2 = imcrop(rgb, [83.5 189.5 453 87]);
rgbImage = X2;
% 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');
% 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 = rgbImage(:, :, :) < 58;
spots = spots(:, :, 1) == spots(:, :, 2) == spots(:, :, 3);
subplot(2, 2, 2);
imshow(spots, []);
title('Thresholded Red Channel');
spots = imclearborder(spots,8);
subplot(2, 2, 3);
imshow(spots, []);
title('Border Cleared');
% Fill holes
spots = imfill(spots, 'holes');
subplot(2, 2, 4);
imshow(spots, []);
title('Final Spots Image');
impixelinfo;
% Count them
L = bwlabel(spots);
[labeledImage ,numberOfSpots] = bwlabel(spots);
message = sprintf('Done!\nThe number of spots (total on both dice) is %d', numberOfSpots);
msgbox(message);


Thanks in advanced.
0 Comments
Answers (1)
See Also
Categories
Find more on Explore and Edit Images with Image Viewer App in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!