How to find X and O using Image Processing toolbox?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Michele Berra
el 11 de Nov. de 2014
Comentada: Image Analyst
el 11 de Nov. de 2014
Dear All,
here is my problem: I have an image with X and O (of different colors) and I need to determine the position of such objects. Precisely, I want to obtain the centers of the circles and the ones of the crosses.
So far, I was able to do it for the circles using imfindcircles. Any idea? I should mention that each object has fixed dimension.
Best, Michele
0 comentarios
Respuesta aceptada
Image Analyst
el 11 de Nov. de 2014
I don't think the easiest way is not to use a template and run it around the image, but if you do want to use that method, see my attached demo.
By far the easiest way is to simply split the image into red, green, and blue channels.
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
Threshold and combine them to get binary images of just the red and green objects. I'll let you do that simple part. Display them first so it will be easier to determine which you need to combine. There's only 3 lines of code you need to do here.
Then simply call bwlabel and regionprops to get the centroids
labeledImage = bwlabel(binaryImage);
measurements = regionprops(labeledImage, 'Centroid');
2 comentarios
Image Analyst
el 11 de Nov. de 2014
The normxcorr2 method requires a known template that you can scan the image with. The simpler color segmentation method does not. Plus the segmentation method does not require complicated indexing to find the location, which normxcorr2 does because the correlated output image is larger than the input image by the width of the template. So a spot at (100,150) will not show up at 100,150 in the output image - it will be shifted over by the width of the template (or is it half width?). I recommend the color segmentation method I showed in the body of my message. However, it just finds colored spots without regard to their shape. It will find red crossed, squares, diamonds, blobs of any shape. If you really need just crosses and not any other thing that's red, then you should use normxcorr2. Since you don't have any other red shapes, this is not something you have to worry about and you can do the simple color segmentation method. See my File Exchange for more color segmentation demos. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
Más respuestas (1)
yonatan gerufi
el 11 de Nov. de 2014
Editada: yonatan gerufi
el 11 de Nov. de 2014
if the X and O have fixed dimension and shape, is to build a mask for X and mask for O, and run it on the picture.
2 comentarios
yonatan gerufi
el 11 de Nov. de 2014
Editada: yonatan gerufi
el 11 de Nov. de 2014
first you should do your picture to binary one using "im2bw". (make sure you pick a threshold that doesn't turn X & O to zeros)
crop small rectangle around the X, and one around O. those are your masks.
now, you should run all over the picture, and sum the matrix results from multiplying the mask with the current part of the picture (a.k.a 2D convolution) this will give you a value, that will be high if the picture and mask are correlated, and you have an X or O pattern.
hopefully it is understandable. regards.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!