how to detect a triangle with anycolor among lots of colorful geometric shapes

1 view (last 30 days)
Hello imagine that i have a image on white background .( like a A4 paper) .assume .i draw grid lines( vertical and horizontal) ..Then draw different colorful geometric shapes (rectangulars , circles ,triangles ..) And i want to detect just red triangles..
may you give an idea how to perform it ?

Answers (1)

Image Analyst
Image Analyst on 21 Apr 2014
First get the shapes. You extract red, green, and blue. Then threshold them to find dark things. Then AND them all together. Now you have a binary image of the shapes. Then call bwboundaries() to get the (x,y) coordinates of the shape perimeters. Then use the FAQ to find kinks in the curve: http://matlab.wikia.com/wiki/FAQ?title=FAQ&cb=4698#How_do_I_find_.22kinks.22_in_a_curve.3F The triangles will have 3 kinks. Good luck.
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Find binary images
redBinaryImage = redChannel < 250;
greenBinaryImage = greenChannel < 250;
blueBinaryImage = blueChannel < 250;
binaryImage = redBinaryImage & greenBinaryImage & blueBinaryImage;
boundaries = bwboundaries(binaryImage);
% Now use the FAQ to find kinks.
It might be easier if you knew all the triangles had the same aspect ratio because you could use regionprops and look at the perimeter squared to shape ratio.

Community Treasure Hunt

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

Start Hunting!