new functions to create masks (to remove borders and center of detector

This commit is contained in:
Marco Cammarata 2017-02-09 16:59:46 +01:00
parent d571c4435f
commit 71cb06128f
1 changed files with 19 additions and 2 deletions

View File

@ -116,7 +116,7 @@ def makeMaskGui(img,snapRange=60):
mask.addRectangle(c1[0],c1[1],c2[0],c2[1]) mask.addRectangle(c1[0],c1[1],c2[0],c2[1])
plt.imshow(mask.getMatplotlibMask()) plt.imshow(mask.getMatplotlibMask())
plt.pause(0.01) plt.pause(0.01)
fname = input("Enter a valid filename (ext .edf or .npy) to save the mask") fname = input("Enter a valid filename (ext .edf or .npy) if you want to save the mask (empty otherwise)")
try: try:
if fname != '': if fname != '':
ext = os.path.splitext(fname)[1] ext = os.path.splitext(fname)[1]
@ -130,7 +130,24 @@ def makeMaskGui(img,snapRange=60):
finally: finally:
return mask return mask
def maskBorder(width,shape):
mask = np.zeros(shape,dtype=bool)
mask[ :width , : ] = True
mask[ -width: , : ] = True
mask[ : , :width ] = True
mask[ : , -width: ] = True
return mask
def maskCenterLines(width,shape):
mask = np.zeros(shape,dtype=bool)
if isinstance(width,int): width = (width,width)
c0 = int(shape[0]/2)
c1 = int(shape[1]/2)
w0 = int(width[0]/2)
w1 = int(width[1]/2)
mask[ c0-w0:c0+w0 , : ] = True
mask[ : , c1-w1:c1+w1 ] = True
return mask
if __name__ == "__main__": if __name__ == "__main__":