Update model/cloth_masker.py
Browse files206 unmodified lines2072082092102112122138 unmodified lines2222232242252262272282297 unmodified lines237238239240241242243244245246247248249250206 unmodified linesschp_atr_mask = np.array(schp_atr_mask)# Strong Protect Area (Hands, Face, Accessory, Feet)hands_protect_area = part_mask_of(['hands', 'feet'], densepose_mask, DENSE_INDEX_MAP)hands_protect_area = cv2.dilate(hands_protect_area, dilate_kernel, iterations=1)hands_protect_area = hands_protect_area & \(part_mask_of(['Left-arm', 'Right-arm', 'Left-leg', 'Right-leg'], schp_atr_mask, ATR_MAPPING) | \8 unmodified linespart_mask_of(['Hair'], schp_atr_mask, ATR_MAPPING)cloth_protect_area = part_mask_of(PROTECT_CLOTH_PARTS[part]['LIP'], schp_lip_mask, LIP_MAPPING) | \part_mask_of(PROTECT_CLOTH_PARTS[part]['ATR'], schp_atr_mask, ATR_MAPPING)accessory_protect_area = part_mask_of((accessory_parts := ['Hat', 'Glove', 'Sunglasses', 'Bag', 'Left-shoe', 'Right-shoe', 'Scarf', 'Socks']), schp_lip_mask, LIP_MAPPING) | \part_mask_of(accessory_parts, schp_atr_mask, ATR_MAPPING)weak_protect_area = body_protect_area | cloth_protect_area | hair_protect_area | strong_protect_area | accessory_protect_area# Mask Area7 unmodified linesmask_area = (np.ones_like(densepose_mask) & (~weak_protect_area) & (~background_area)) | mask_dense_areamask_area = hull_mask(mask_area * 255) // 255 # Convex Hull to expand the mask areamask_area = mask_area & (~weak_protect_area)mask_area = cv2.GaussianBlur(mask_area * 255, (kernal_size, kernal_size), 0)mask_area[mask_area < 25] = 0mask_area[mask_area >= 25] = 1mask_area = (mask_area | strong_mask_area) & (~strong_protect_area)mask_area = cv2.dilate(mask_area, dilate_kernel, iterations=1)return Image.fromarray(mask_area * 255)206 unmodified lines2072082092102112122132142152168 unmodified lines2252262272282292302312322332342352367 unmodified lines244245246247248249250206 unmodified linesschp_atr_mask = np.array(schp_atr_mask)# Strong Protect Area (Hands, Face, Accessory, Feet)if part == "overall":hands_protect_area = part_mask_of(['hands',], densepose_mask, DENSE_INDEX_MAP)else:hands_protect_area = part_mask_of(['hands', 'feet'], densepose_mask, DENSE_INDEX_MAP)hands_protect_area = cv2.dilate(hands_protect_area, dilate_kernel, iterations=1)hands_protect_area = hands_protect_area & \(part_mask_of(['Left-arm', 'Right-arm', 'Left-leg', 'Right-leg'], schp_atr_mask, ATR_MAPPING) | \8 unmodified linespart_mask_of(['Hair'], schp_atr_mask, ATR_MAPPING)cloth_protect_area = part_mask_of(PROTECT_CLOTH_PARTS[part]['LIP'], schp_lip_mask, LIP_MAPPING) | \part_mask_of(PROTECT_CLOTH_PARTS[part]['ATR'], schp_atr_mask, ATR_MAPPING)if part == "overall":accessory_protect_area = part_mask_of((accessory_parts := ['Hat', 'Glove', 'Sunglasses', 'Bag', 'Scarf', 'Socks']), schp_lip_mask, LIP_MAPPING) | \part_mask_of(accessory_parts, schp_atr_mask, ATR_MAPPING)else:accessory_protect_area = part_mask_of((accessory_parts := ['Hat', 'Glove', 'Sunglasses', 'Bag', 'Left-shoe', 'Right-shoe', 'Scarf', 'Socks']), schp_lip_mask, LIP_MAPPING) | \part_mask_of(accessory_parts, schp_atr_mask, ATR_MAPPING)weak_protect_area = body_protect_area | cloth_protect_area | hair_protect_area | strong_protect_area | accessory_protect_area# Mask Area7 unmodified linesmask_area = (np.ones_like(densepose_mask) & (~weak_protect_area) & (~background_area)) | mask_dense_areamask_area = (mask_area | strong_mask_area) & (~strong_protect_area)return Image.fromarray(mask_area * 255)
model/cloth_masker.py+10-10