run-youngjoo/SC-FEGAN

reading a Custom Mask

PaperKites opened this issue · 0 comments

I'm trying to give the model a custom mask but the doesn't give the expected results even tho the model give a good result with provided mask (using the mask button).

    def make_mask(self, pts, mslice,i):
        if len(pts)>0:
            mask = np.zeros((512,512,3))
            for pt in pts:
                cv2.line(mask,pt['prev'],pt['curr'],(255,255,255),12)
            mask = np.asarray(mask[:,:,0]/255,dtype=np.uint8)
            mask = np.expand_dims(mask,axis=2)
            mask = np.expand_dims(mask,axis=0)
    else:
        # loading the mask from matlab file {1=hole} 
        array2D= scipy.io.loadmat('data.mat')['Holes_Vol']

        # resize the 2d matrix
        mask = cv2.resize(mslice, (512, 512), interpolation=cv2.INTER_CUBIC)

        #  convert the matrix to 3 chanels (3D) (RGB)
        mask = np.repeat(mask[:, :, np.newaxis]*255, 3, axis=2)

        # The below line are taken from the 3 line above else
        mask = np.asarray(mask[:,:,0]/255,dtype=np.uint8)
        mask = np.expand_dims(mask,axis=2)
        mask = np.expand_dims(mask,axis=0)
        
    return mask 

The code before the modification:

SC-FEGAN/demo.py

Lines 146 to 159 in 5a2992e

def make_mask(self, pts):
if len(pts)>0:
mask = np.zeros((512,512,3))
for pt in pts:
cv2.line(mask,pt['prev'],pt['curr'],(255,255,255),12)
mask = np.asarray(mask[:,:,0]/255,dtype=np.uint8)
mask = np.expand_dims(mask,axis=2)
mask = np.expand_dims(mask,axis=0)
else:
mask = np.zeros((512,512,3))
mask = np.asarray(mask[:,:,0]/255,dtype=np.uint8)
mask = np.expand_dims(mask,axis=2)
mask = np.expand_dims(mask,axis=0)
return mask

any suggestions?