def anonymizeFace(filePathMhd):
    if RM_FACE_CUT_OFF <= 0:
        return

    cutOff = 0.15


    mhdFile=CxDataHandler.mhdFile(filePathMhd)
    if 'Modality'not in mhdFile.Params:
        if not 'MR'in filePathMhd:
            return
    elif not mhdFile.Params['Modality'] == 'MR':
        return
    elif not mhdFile.get_DimSize() == 3:
        pass        
        #return
    
    print filePathMhd
    data=mhdFile.get_samples()
    
   
    X=[]
    Y=[]
    Z=[]
    for x in range(data.shape[0]):
        for y in range(data.shape[1]):
            for z in range(data.shape[2]):
                if data[x,y,z]>1:
                    X.append(x)
                    Y.append(y)
                    Z.append(z)
    
    x_com=np.mean(X)
    y_com=np.mean(Y)
    z_com=np.mean(Z)

    def avgElAboveLimit(plane,limit=10):
        res=0
        for i in range(plane.shape[0]):
            for j in range(plane.shape[1]):
                    if plane[i,j]>limit:
                        res=res+1
        return res/float(plane.shape[0]*plane.shape[1])
        
        
    def findN(vec):
        temp=None
        k=0
        for el in vec:
            if not temp and el > 0.015:
                temp=k
            if temp and el >cutOff:
                return k
                return k-temp
            k=k+1

        
    x=[]
    for i in range(data.shape[0]):
        temp=avgElAboveLimit(data[i,:,:])
        x.append(temp)
    x1=findN(x)            
    x2=findN(x[::-1])

    y=[]        
    for i in range(data.shape[1]):
        temp=avgElAboveLimit(data[:,i,:])
        y.append(temp)
    y1=findN(y)            
    y2=findN(y[::-1])   

    z=[]
    z1=None
    z2=None
    for i in range(data.shape[2]):
        temp=avgElAboveLimit(data[:,:,i])
        z.append(temp)
    z1=findN(z)            
    z2=findN(z[::-1])

    import matplotlib.pyplot as plt    
    
    plt.plot(x)
    plt.show()  
    print x1,x2
    plt.plot(y)
    plt.show()  
    print y1,y2
    plt.plot(z)
    plt.show()  
    print z1,z2

    print
    print x_com
    print y_com
    print z_com
    
    
    I00=0
    I11=0
    I22=0
    I01=0
    I12=0
    I02=0
    
    Ixx=0
    Iyy=0
    Izz=0
    
    for i in range(len(X)):
        I00=I00+(Y[i]-y_com)**2+(Z[i]-z_com)**2
        I11=I11+(X[i]-x_com)**2+(Z[i]-z_com)**2
        I22=I22+(X[i]-x_com)**2+(Y[i]-y_com)**2
        I01=I01+(X[i]-x_com)*(Y[i]-y_com)
        I12=I12+(Y[i]-y_com)*(Z[i]-z_com)
        I02=I02+(X[i]-x_com)*(Z[i]-z_com)
        
        Ixx=Ixx+(X[i]-x_com)*(X[i]-x_com)
        Iyy=Iyy+(Y[i]-y_com)*(Y[i]-y_com)
        Izz=Izz+(Z[i]-z_com)*(Z[i]-z_com)


    I00=I00/len(X)
    I11=I11/len(X)
    I22=I22/len(X)
    I01=I01/len(X)
    I12=I12/len(X)
    I02=I02/len(X)
    
    Ixx=Ixx/len(X)    
    Iyy=Iyy/len(X)    
    Izz=Izz/len(X)
    
    print
    
    print Ixx
    print Iyy
    print Izz
    
    print    
    
    print I00
    print I11
    print I22
    print
    print I01
    print I12
    print I02    
    

    return 

    if idx==0 and lvec(idx)>0: 
        N=int(RM_FACE_CUT_OFF/mhdFile.get_spacing()[0])
        data[0:N,:,:]=0
    if idx==0 and lvec(idx)<0:
        N=int(RM_FACE_CUT_OFF/mhdFile.get_spacing()[0])
        data[-N:,:,:]=0
    if idx==1 and lvec(idx)>0:
        N=int(RM_FACE_CUT_OFF/mhdFile.get_spacing()[1])
        data[:,0:N,:]=0
    if idx==1 and lvec(idx)<0:
        N=int(RM_FACE_CUT_OFF/mhdFile.get_spacing()[1])
        data[:,-N:,:]=0
    if idx==2 and lvec(idx)>0:
        N=int(RM_FACE_CUT_OFF/mhdFile.get_spacing()[2])
        data[:,:,0:N]=0
    if idx==2 and lvec(idx)<0:
        N=int(RM_FACE_CUT_OFF/mhdFile.get_spacing()[2])
        data[:,:,-N:]=0
        
    CxDataHandler.rawFileWrither(mhdFile.getRawFilePath(),data,color=False,ElementType=mhdFile.get_ElementType())
def anonymizeFace(filePathMhd):
    if RM_FACE_CUT_OFF <= 0:
        return

    cutOff = 0.15

    mhdFile = CxDataHandler.mhdFile(filePathMhd)
    if 'Modality' not in mhdFile.Params:
        if not 'MR' in filePathMhd:
            return
    elif not mhdFile.Params['Modality'] == 'MR':
        return
    elif not mhdFile.get_DimSize() == 3:
        pass
        #return

    print filePathMhd
    data = mhdFile.get_samples()

    X = []
    Y = []
    Z = []
    for x in range(data.shape[0]):
        for y in range(data.shape[1]):
            for z in range(data.shape[2]):
                if data[x, y, z] > 1:
                    X.append(x)
                    Y.append(y)
                    Z.append(z)

    x_com = np.mean(X)
    y_com = np.mean(Y)
    z_com = np.mean(Z)

    def avgElAboveLimit(plane, limit=10):
        res = 0
        for i in range(plane.shape[0]):
            for j in range(plane.shape[1]):
                if plane[i, j] > limit:
                    res = res + 1
        return res / float(plane.shape[0] * plane.shape[1])

    def findN(vec):
        temp = None
        k = 0
        for el in vec:
            if not temp and el > 0.015:
                temp = k
            if temp and el > cutOff:
                return k
                return k - temp
            k = k + 1

    x = []
    for i in range(data.shape[0]):
        temp = avgElAboveLimit(data[i, :, :])
        x.append(temp)
    x1 = findN(x)
    x2 = findN(x[::-1])

    y = []
    for i in range(data.shape[1]):
        temp = avgElAboveLimit(data[:, i, :])
        y.append(temp)
    y1 = findN(y)
    y2 = findN(y[::-1])

    z = []
    z1 = None
    z2 = None
    for i in range(data.shape[2]):
        temp = avgElAboveLimit(data[:, :, i])
        z.append(temp)
    z1 = findN(z)
    z2 = findN(z[::-1])

    import matplotlib.pyplot as plt

    plt.plot(x)
    plt.show()
    print x1, x2
    plt.plot(y)
    plt.show()
    print y1, y2
    plt.plot(z)
    plt.show()
    print z1, z2

    print
    print x_com
    print y_com
    print z_com

    I00 = 0
    I11 = 0
    I22 = 0
    I01 = 0
    I12 = 0
    I02 = 0

    Ixx = 0
    Iyy = 0
    Izz = 0

    for i in range(len(X)):
        I00 = I00 + (Y[i] - y_com)**2 + (Z[i] - z_com)**2
        I11 = I11 + (X[i] - x_com)**2 + (Z[i] - z_com)**2
        I22 = I22 + (X[i] - x_com)**2 + (Y[i] - y_com)**2
        I01 = I01 + (X[i] - x_com) * (Y[i] - y_com)
        I12 = I12 + (Y[i] - y_com) * (Z[i] - z_com)
        I02 = I02 + (X[i] - x_com) * (Z[i] - z_com)

        Ixx = Ixx + (X[i] - x_com) * (X[i] - x_com)
        Iyy = Iyy + (Y[i] - y_com) * (Y[i] - y_com)
        Izz = Izz + (Z[i] - z_com) * (Z[i] - z_com)

    I00 = I00 / len(X)
    I11 = I11 / len(X)
    I22 = I22 / len(X)
    I01 = I01 / len(X)
    I12 = I12 / len(X)
    I02 = I02 / len(X)

    Ixx = Ixx / len(X)
    Iyy = Iyy / len(X)
    Izz = Izz / len(X)

    print

    print Ixx
    print Iyy
    print Izz

    print

    print I00
    print I11
    print I22
    print
    print I01
    print I12
    print I02

    return

    if idx == 0 and lvec(idx) > 0:
        N = int(RM_FACE_CUT_OFF / mhdFile.get_spacing()[0])
        data[0:N, :, :] = 0
    if idx == 0 and lvec(idx) < 0:
        N = int(RM_FACE_CUT_OFF / mhdFile.get_spacing()[0])
        data[-N:, :, :] = 0
    if idx == 1 and lvec(idx) > 0:
        N = int(RM_FACE_CUT_OFF / mhdFile.get_spacing()[1])
        data[:, 0:N, :] = 0
    if idx == 1 and lvec(idx) < 0:
        N = int(RM_FACE_CUT_OFF / mhdFile.get_spacing()[1])
        data[:, -N:, :] = 0
    if idx == 2 and lvec(idx) > 0:
        N = int(RM_FACE_CUT_OFF / mhdFile.get_spacing()[2])
        data[:, :, 0:N] = 0
    if idx == 2 and lvec(idx) < 0:
        N = int(RM_FACE_CUT_OFF / mhdFile.get_spacing()[2])
        data[:, :, -N:] = 0

    CxDataHandler.rawFileWrither(mhdFile.getRawFilePath(),
                                 data,
                                 color=False,
                                 ElementType=mhdFile.get_ElementType())