fenglinglwb / MAT

MAT: Mask-Aware Transformer for Large Hole Image Inpainting
Other
766 stars 85 forks source link

Problem with grayscale image training #93

Open javak87 opened 1 year ago

javak87 commented 1 year ago

Dear Developer, I want to use grayscale images to train a network, after running I can see the RGB mask on grayscale images which is not my interest. I want to apply a binary mask. Here is the mask and images after masking: Screenshot from 2023-07-22 10-19-53 Images Screenshot from 2023-07-22 10-20-06 Masks

Could you please tell me how can I get rid of RGB mask and use the binary mask? Thanks

nguyenlamvu123 commented 1 year ago

you can use opencv to create binary mask

` def create_mask_by_threshold(im=None, s=None, method=cv2.THRESH_BINARY, thres=220, mpath=""):

    if im is None:

        im = cv2.imread(os.path.join(...))

    mask = 'result1.png' if s is None else os.path.join(mpath, s)

    img = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)  # it will be a RGB mask without cv2.COLOR_BGR2GRAY flag 

    blurred = cv2.GaussianBlur(img, (7, 7), 0)

    _, img_masked = cv2.threshold(blurred, thres, 255, method)

    cv2.imwrite(mask, img_masked)`
javak87 commented 1 year ago

Great. Thanks