From 71cb06128fba9b870a7b8db127bf02e0449b0c19 Mon Sep 17 00:00:00 2001 From: Marco Cammarata Date: Thu, 9 Feb 2017 16:59:46 +0100 Subject: [PATCH] new functions to create masks (to remove borders and center of detector --- xray/mask.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/xray/mask.py b/xray/mask.py index 5f55e87..ea51c60 100644 --- a/xray/mask.py +++ b/xray/mask.py @@ -116,7 +116,7 @@ def makeMaskGui(img,snapRange=60): mask.addRectangle(c1[0],c1[1],c2[0],c2[1]) plt.imshow(mask.getMatplotlibMask()) 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: if fname != '': ext = os.path.splitext(fname)[1] @@ -130,7 +130,24 @@ def makeMaskGui(img,snapRange=60): finally: 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__":