您的位置:首页 > 其它

不规则ROI

2015-06-28 18:36 232 查看
原文:http://blog.csdn.net/xuelin273/article/details/4336064

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.



Fig 1. Selecting circular ROI and applying some processing on it.

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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: