(mask)
| 405 | |
| 406 | |
| 407 | def dilate_erode_mask(mask): |
| 408 | mask = cv2.resize(mask, (512, 512)) |
| 409 | rand_dilate_erod = random.random() |
| 410 | if rand_dilate_erod < 0.5: # dilate |
| 411 | kernel = np.ones((3, 3), np.uint8) |
| 412 | iterations = random.randint(1, 5) |
| 413 | dilated_image = cv2.dilate(mask, kernel, iterations=iterations) |
| 414 | # mask = dilated_image |
| 415 | random_x = random.randint(100, 400) |
| 416 | if random.random() < 0.5: |
| 417 | ###only dilate part of mask, avoid the entire mask shape not changing but only getting bigger |
| 418 | mask[:, random_x:min(random_x + 256, 511)] = dilated_image[:, random_x:min(random_x + 256, 511)] |
| 419 | else: |
| 420 | mask[random_x:min(random_x + 256, 511), :] = dilated_image[random_x:min(random_x + 256, 511), :] |
| 421 | elif rand_dilate_erod < 0.8: #erode |
| 422 | kernel = np.ones((3, 3), np.uint8) |
| 423 | iterations = random.randint(1, 2) |
| 424 | eroded_image = cv2.erode(mask, kernel, iterations=iterations) |
| 425 | random_x = random.randint(100, 400) |
| 426 | if random.random() < 0.5: |
| 427 | mask[:, random_x:min(random_x + 256, 511)] = eroded_image[:, random_x:min(random_x + 256, 511)] |
| 428 | else: |
| 429 | mask[random_x:min(random_x + 256, 511), :] = eroded_image[random_x:min(random_x + 256, 511), :] |
| 430 | return mask |
| 431 | |
| 432 | |
| 433 | #from pytorch3d |
nothing calls this directly
no outgoing calls
no test coverage detected