Spaces:
Sleeping
Sleeping
Upload Colony_Analyzer_AI_zstack2_HF.py
Browse files
Colony_Analyzer_AI_zstack2_HF.py
CHANGED
|
@@ -154,17 +154,20 @@ def contours_overlap_using_mask(contour1, contour2, image_shape=(1536, 2048)):
|
|
| 154 |
|
| 155 |
return np.any(overlap)
|
| 156 |
|
| 157 |
-
def analyze_colonies(mask, size_cutoff, circ_cutoff):
|
| 158 |
-
colonies
|
| 159 |
necrosis = find_necrosis(mask)
|
| 160 |
|
| 161 |
data = []
|
| 162 |
|
| 163 |
-
for
|
| 164 |
-
|
| 165 |
-
colony_area = areas[x]
|
| 166 |
centroid = compute_centroid(colony)
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
# Check if any necrosis contour is inside the colony
|
| 169 |
necrosis_area = 0
|
| 170 |
nec_list =[]
|
|
@@ -181,7 +184,8 @@ def analyze_colonies(mask, size_cutoff, circ_cutoff):
|
|
| 181 |
"centroid": centroid,
|
| 182 |
"percent_necrotic": necrosis_area/colony_area,
|
| 183 |
"contour": colony,
|
| 184 |
-
"nec_contours": nec_list
|
|
|
|
| 185 |
})
|
| 186 |
|
| 187 |
# Convert results to a DataFrame
|
|
@@ -256,7 +260,7 @@ def main(args):
|
|
| 256 |
img_map[z] = eval_img(img_map[z])
|
| 257 |
del z
|
| 258 |
p = stitch(img_map)
|
| 259 |
-
frame = analyze_colonies(p, min_size, min_circ)
|
| 260 |
frame["source"] = idx
|
| 261 |
frame["exclude"] = False
|
| 262 |
if isinstance(colonies, dict):
|
|
|
|
| 154 |
|
| 155 |
return np.any(overlap)
|
| 156 |
|
| 157 |
+
def analyze_colonies(mask, size_cutoff, circ_cutoff, img):
|
| 158 |
+
colonies = find_colonies(mask, size_cutoff, circ_cutoff)
|
| 159 |
necrosis = find_necrosis(mask)
|
| 160 |
|
| 161 |
data = []
|
| 162 |
|
| 163 |
+
for colony in colonies:
|
| 164 |
+
colony_area = cv2.contourArea(colony)
|
|
|
|
| 165 |
centroid = compute_centroid(colony)
|
| 166 |
+
if colony_area <= 50:
|
| 167 |
+
continue
|
| 168 |
+
mask = np.zeros(img.shape, np.uint8)
|
| 169 |
+
cv2.drawContours(mask, [colony], -1, 255, cv2.FILLED)
|
| 170 |
+
pix = img[mask == 255]
|
| 171 |
# Check if any necrosis contour is inside the colony
|
| 172 |
necrosis_area = 0
|
| 173 |
nec_list =[]
|
|
|
|
| 184 |
"centroid": centroid,
|
| 185 |
"percent_necrotic": necrosis_area/colony_area,
|
| 186 |
"contour": colony,
|
| 187 |
+
"nec_contours": nec_list,
|
| 188 |
+
'mean_pixel_value':np.mean(pix)
|
| 189 |
})
|
| 190 |
|
| 191 |
# Convert results to a DataFrame
|
|
|
|
| 260 |
img_map[z] = eval_img(img_map[z])
|
| 261 |
del z
|
| 262 |
p = stitch(img_map)
|
| 263 |
+
frame = analyze_colonies(p, min_size, min_circ, files[idx])
|
| 264 |
frame["source"] = idx
|
| 265 |
frame["exclude"] = False
|
| 266 |
if isinstance(colonies, dict):
|