A few days ago, a reader asked me about selecting circular ROI using OpenCV. I think such a function for selecting non-rectangular subimage would be useful, so I tried to write one.
OpenCV doesn't provide a function to make non-rectangle ROI, so I use image mask to do the trick. It works like this. say we have two images:
img - an RGB image.mask - a black image, with white circle on it.We can extract a region from img by:
res = img & mask
res now contains a portion from img where the white circle is located.

The full listing is shown below. The code loads an image, select circular ROI, and applying some processing on it.
Listing 1: Extract a circular ROI
In the example above, I only invert the subimage to make it simple. Change the line 39 with more complex image processing.
Learning OpenCV: Computer Vision with the OpenCV Library
By: Gary Bradski, Adrian Kaehler
This book is the "de facto" OpenCV User's Manual. It provides a practical, pragmatic, accessible book on computer vision, with algorithmic explanation and concrete example code snippets. Written by the creators of OpenCV, no doubt you should obtain a copy.
Machine Vision: Theory, Algorithms, Practicalities (Signal Processing and its Applications)
By: E. R. Davies
This book provides a solid and concrete foundation to computer vision from engineering point of view. Use Learning OpenCV from Gary Bradsky to learn how to use OpenCV, and use this book to understand how OpenCV works behind the screen.
Chaniel on Jul 2, 2010:
Nathan Crock on Sep 30, 2010:
momin on Aug 1, 2011:
| ICQ | 489571630 |
| Skype | dede_bl4ckheart |
| Yahoo | dede_bl4ckheart |
| nashruddin.amin |
anika on Apr 5, 2010:
Can you suggest me how can I select a circular region from an image using mouse? I badly need your help.
Anika