How to remove the shadow and count the number of dices in the image

2 views (last 30 days)
Hi all, I am new to image processing with matlab.
I am trying to count the number of dice, the total number of groups of dices from the image.
In the image, there are 3 different colors of dice, background full of noise and shadow which makes the problem harder.
How can I solve this problem? Should I extract them according to color or remove the shadow then binarize the image. I have totally no idea how to start.
This is the code I used but I don't think it's correct.
close all
img1=imread('Dice.jpg');
imshow(img1)
img1=rgb2hsv(img1);
img2=img1(:,:,3);
thresholded=img2>0.1;
thresholded=bwareaopen(thresholded,5);
img3=thresholded.*img2;
img4=edge(img3,'canny',graythresh(img3));
img4=imfill(img4,'hole');
figure,imagesc(img4)
B = bwboundaries(img4);
imshow(img4)
text(10,10,strcat('\color{green}Objects Found:',num2str(length(B))))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'g', 'LineWidth', 0.2)
end

Answers (0)

Community Treasure Hunt

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

Start Hunting!