Open WNjun opened 8 months ago
@WNjun Hello. Thanks for your interest in your study. AllSlide is a private code belonging to our co-author; hence it is not publicly available. Yet, all of the functions in Allslide are actually based on OpenSlide. You can try to replace AllSlide functions with OpenSlide functions. If you check the code 1-2-1.segment_tiles.py, you will find only three positions mentioned in AllSlide; I can share detailed explanations so that you can reproduce the necessary code easily:
(1)im_slide = AllSlide.AllSlide(sp)
: you can replace it as im_slide = openslide.open_slide(sp)
(2) msk = im_slide.get_foreground_mask(im_slide.level_dimensions[-1])
: get_foreground_mask is a function that uses the OTSU algorithm to segment the foreground and the background. The function will finally generate a binary mask.
The pseudocode is provided as follows:
def get_foreground_mask(img_slide, size):
dimensions = img_slide.level_dimensions
lv_id = len(dimensions) - 1
img = np.array(img_slide.read_region((0, 0), lv_id, size))[:, :, :3]
# you can easily find an OTSU algorithm code from Github or other sources.
mask = otsu(img)
return mask
The input of otsu( ) function is an image array as provided in the pseudocode, and the output of otsu( ) function is a binary-mask. The foreground is represented by white pixels, while the background is represented by black pixels. After you finish the above code, you also need to modify the original code as msk = im_slide.get_foreground_mask(im_slide, im_slide.level_dimensions[-1])
(3) patch = im_slide.read_region(ele,0,(patch_size,patch_size)).convert('RGB')
: read_region
is a function of OpenSlide, you can use this code without modification. To find more details about read_region, you can check OpenSlide documents.
Please feel free to let me know if you have any other questions. Also, please cite our article if you find any part of our code useful for your project. Hopefully my response is helpful for your project.
Bests, Kexin
Thank you for your detailed explaination! Appreciate it!
Hi! When I try to run
1-2-1.segment_tiles.py
the program failed with error:ModuleNotFoundError: No module named 'AllSlide'
I have searched through the repository but couldn't find an implementation or reference to an "AllSlide" module or package. Could you please help by providing the implementation of "AllSlide"?
Thank you very much for your time and help.