I would do this by converting from Cartesian coordinates to polar and building Boolean masks for the circle and for the range of angles you want:
import numpy as np def sector_mask(shape,centre,radius,angle_range): """ Return a boolean mask for a circular sector. The start/stop angles in `angle_range` should be given in clockwise order. """ x,y = np.ogrid[:shape[0],:shape[1]] cx,cy = centre tmin,tmax = np.deg2rad(angle_range) # ensure stop angle > start angle if tmax < tmin: tmax += 2*np.pi # convert cartesian --> polar coordinates r2 = (x-cx)*(x-cx) + (y-cy)*(y-cy) theta = np.arctan2(x-cx,y-cy) - tmin # wrap angles between 0 and 2*pi theta %= (2*np.pi) # circular mask circmask = r2 <= radius*radius # angular mask anglemask = theta <= (tmax-tmin) return circmask*anglemask
For example:
from matplotlib import pyplot as pp from scipy.misc import lena matrix = lena() mask = sector_mask(matrix.shape,(200,100),300,(0,50)) matrix[~mask] = 0 pp.imshow(matrix) pp.show()

ali_m
source share