|
1 | 1 | import warnings |
2 | 2 | import numpy as np |
3 | | -from imageio.v2 import imsave |
4 | 3 | from skimage.measure import regionprops |
5 | 4 | from scipy.ndimage.morphology import grey_dilation |
6 | 5 | import pandas as pd |
7 | 6 | import image_utils |
| 7 | +import cv2 |
8 | 8 |
|
9 | 9 |
|
10 | 10 | warnings.simplefilter(action="ignore", category=FutureWarning) |
@@ -83,28 +83,28 @@ def generate_crops(image_stack, cell_mask, nuclei_mask, crop_size, crop_bitdepth |
83 | 83 | this_cell_mask[this_cell_mask == region.label] = 1 |
84 | 84 | this_cell_mask = grey_dilation(this_cell_mask, size=7) |
85 | 85 | curr_cell_mask, _ = safe_crop(this_cell_mask, fixed_bbox) |
86 | | - imsave(f"{output_folder}/{output_prefix}cell{region.label}_cellmask.png", np.uint8(curr_cell_mask * 255)) |
| 86 | + cv2.imwrite(f"{output_folder}/{output_prefix}cell{region.label}_cellmask.png", np.uint8(curr_cell_mask * 255)) |
87 | 87 | if nuclei_mask is not None: |
88 | 88 | this_nuclei_mask = nuclei_mask.copy() |
89 | 89 | this_nuclei_mask[this_nuclei_mask != region.label] = 0 |
90 | 90 | this_nuclei_mask[this_nuclei_mask == region.label] = 1 |
91 | 91 | this_nuclei_mask = grey_dilation(this_nuclei_mask, size=7) |
92 | 92 | curr_nuclei_mask, _ = safe_crop(this_nuclei_mask, fixed_bbox) |
93 | | - imsave(f"{output_folder}/{output_prefix}cell{region.label}_nucleimask.png", np.uint8(curr_nuclei_mask * 255)) |
| 93 | + cv2.imwrite(f"{output_folder}/{output_prefix}cell{region.label}_nucleimask.png", np.uint8(curr_nuclei_mask * 255)) |
94 | 94 |
|
95 | 95 | for curr_img_index in range(len(image_stack)): |
96 | 96 | if curr_img_index != 0: |
97 | 97 | image_cp = image_stack[curr_img_index][0].copy() |
98 | 98 |
|
99 | 99 | cell_crop, _ = safe_crop(image_cp, fixed_bbox) |
100 | | - imsave(f"{output_folder}/{output_prefix}cell{region.label}_crop_" + colors[curr_img_index] + ".png", image_utils.convert_bitdepth(cell_crop, crop_bitdepth)) |
| 100 | + cv2.imwrite(f"{output_folder}/{output_prefix}cell{region.label}_crop_" + colors[curr_img_index] + ".png", image_utils.convert_bitdepth(cell_crop, crop_bitdepth)) |
101 | 101 |
|
102 | 102 | if mask_cell: |
103 | 103 | this_cell_mask = cell_mask == region.label |
104 | 104 | this_cell_mask = grey_dilation(this_cell_mask, size=7) |
105 | 105 | image_cp[this_cell_mask == 0] = 0 |
106 | 106 | cell_mask_crop, _ = safe_crop(image_cp, fixed_bbox) |
107 | | - imsave(f"{output_folder}/{output_prefix}cell{region.label}_crop_masked_" + colors[curr_img_index] + ".png", image_utils.convert_bitdepth(cell_mask_crop, crop_bitdepth)) |
| 107 | + cv2.imwrite(f"{output_folder}/{output_prefix}cell{region.label}_crop_masked_" + colors[curr_img_index] + ".png", image_utils.convert_bitdepth(cell_mask_crop, crop_bitdepth)) |
108 | 108 |
|
109 | 109 | new_center = (crop_size // 2, crop_size // 2) |
110 | 110 | new_bbox = ( |
|
0 commit comments