How to mask circular area ?

asked 2015-12-08 11:10:45 -0600

akif gravatar image

Hi there, I am trying to mask circular area in image.I put the code and the output image.As you can see,I draw the circle around iris.After this point,I want to black out everything outside circular area.How do I need to continue?Are there another ways to do so?

Thanks...

import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('i1.jpg',0)
img = cv2.medianBlur(img,5)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,120,
                        param1=50,param2=50,minRadius=30,maxRadius=0)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
     # draw the outer circle
     cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
     # draw the center of the circle
     cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
cv2.imwrite("iris.jpg",cimg)
plt.imshow(cimg, cmap = 'gray', interpolation = 'bicubic')
plt.xticks([]), plt.yticks([])  # to hide tick values on X and Y axis
plt.show()

image description

edit retag flag offensive close merge delete

Comments

1

I don't know how to do in python but in C++ you can do like this : Init ( a mask) new white image CV_8CU (all pixels 255), filled you circle in black (0) after used set function w

LBerger gravatar imageLBerger ( 2015-12-08 14:14:16 -0600 )edit