mahmoodlab / CLAM

Data-efficient and weakly supervised computational pathology on whole slide images - Nature Biomedical Engineering
http://clam.mahmoodlab.org
GNU General Public License v3.0
1.02k stars 340 forks source link

Problem with process_contour function when contour is None #183

Closed loic-lb closed 5 months ago

loic-lb commented 1 year ago

Hello,

Unless I have missed something, it seems to me that the level should be set to 0 if no contour is provided to the process_contour function, and not to patch level for w,h computation. Indeed, with the actual implementation, you would then assume that the coordinates for reading patches are set to the level patch_level (because stop_x and stop_y would then be equal to the dimension of the slide at patch_level) whereas they always have to be set to the level 0 (cf. openslide documentation) for read_region method.

def process_contour(self, cont, contour_holes, patch_level, save_path, patch_size = 256, step_size = 256,
        contour_fn='four_pt', use_padding=True, top_left=None, bot_right=None):
        start_x, start_y, w, h = cv2.boundingRect(cont) if cont is not None else (0, 0, self.level_dim[ patch_level][0], self.level_dim[patch_level][1])

I would like to point out this detail since it made me struggle to adapt this part of the code to my own pipeline in case someone encounters the same problem.