def select_regoin(img, vert, keep_shape=True, qmask=None, ):
'''Get a pixellist by a rectangular region
defined by
verts e.g. xs,xe,ys,ye = vert #x_start, x_end, y_start,y_end
(dimy, dimx,) = img.shape
Giving cut postion, start, end, width '''
import numpy as np
xs,xe,ys,ye = vert
if keep_shape:
img_= np.zeros_like( img )
#img_= np.zeros( [dimy,dimx])
try:
img_[ys:ye, xs:xe] = True
except:
img_[ys:ye, xs:xe,:] = True
pixellist_ = np.where( img_.ravel() )[0]
#pixellist_ = img_.ravel()
if qmask is not None:
b=np.where( qmask.flatten()==False )[0]
pixellist_ = np.intersect1d(pixellist_,b)
#imgx = img[pixellist_]
#imgx = imgx.reshape( xe-xs, ye-ys)
imgx = img_.ravel()
imgx[pixellist_] = img.ravel()[pixellist_]
imgx = imgx.reshape( img.shape )
else:
try:
imgx =img[ys:ye, xs:xe]
except:
imgx =img[ys:ye, xs:xe,:]
return imgx
评论列表
文章目录