Skip to content

Commit 0cb8883

Browse files
committed
Add Exception for image size not matching configured size, and Warning for cell boxes outside the image
1 parent 08aa86a commit 0cb8883

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

deepprofiler/imaging/cropping.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,15 @@ def prepare_image(self, session, image_array, meta, sample_first_crops=False):
332332
self.input_variables["mask_ind_ph"]: mask_ind
333333
}
334334

335+
# check that all boxes overlap the image
336+
ymins = boxes[:, [0, 2]].min(axis=1)
337+
ymaxs = boxes[:, [0, 2]].max(axis=1)
338+
xmins = boxes[:, [1, 3]].min(axis=1)
339+
xmaxs = boxes[:, [1, 3]].max(axis=1)
340+
if (np.any(ymins > 1) or np.any(xmins > 1) or
341+
np.any(ymaxs < 0) or np.any(ymaxs < 0)):
342+
print("WARNING: Some cell boxes are entirely outside the image")
343+
335344
for i in range(num_targets):
336345
tname = "target_" + str(i)
337346
feed_dict[self.input_variables["targets_phs"][tname]] = targets[i]

deepprofiler/learning/profiling.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ def extract_features(self, key, image_array, meta): # key is a placeholder
8282
if total_crops == 0:
8383
print("No cells to profile:", output_file)
8484
return
85+
86+
# check image size matches config
87+
if (self.config["dataset"]["images"]["width"] != image_array.shape[1] or
88+
self.config["dataset"]["images"]["height"] != image_array.shape[0]):
89+
config_shape = (self.config["dataset"]["images"]["width"],
90+
self.config["dataset"]["images"]["height"])
91+
im_shape = (image_array.shape[1], image_array.shape[0])
92+
raise ValueError("Loaded image shape WxH " + str(im_shape) +
93+
" != configured image shape WxH " + str(config_shape))
94+
8595
repeats = self.config["train"]["model"]["crop_generator"] in ["repeat_channel_crop_generator", "individual_channel_cropgen"]
8696

8797
# Extract features

0 commit comments

Comments
 (0)