# this file recursively performs the automated segmentation of WSIs by applying the tissue segmentation and structure segmentation CNN to all WSIs contained in a specified folder
# extract the WSI level that is closest to the target spacing of the tissue segmentation network (increasing efficiency instead of simply taking full resolution, finest level 0)
logger.info('Image size resampled to FG spacing would be {}, {}, thus level {} with resolution {} chosen as resampling point!'.format(x_scaled,y_scaled,usedLevel,levelDims[usedLevel]))
smallOverlappingPatches=patchify(imgWSIzeropadded,patch_size=(patchImgSize_FG,patchImgSize_FG,3),step=patchImgSize_FG)# CARE: IMAGE DATA AT THE RIGHT AND BOTTOM BORDERS IS LOST !!!
tileDataset=[]
# with tqdm(total=smallOverlappingPatches.shape[0] * smallOverlappingPatches.shape[1]) as pbar:
labeledRegions=cv2.resize(labeledRegions,dsize=(levelDims[0][0],levelDims[0][1]),interpolation=cv2.INTER_NEAREST)# FG RESULTS ON WSI-RESOLUTION, UINT8, REGION IDs
logger.info('In total -> '+str(numberFGRegions)+' <- regions on WSI detected!')
# process all detected tissue regions separately
forregionIDinrange(1,numberFGRegions+1):
logger.info('#######\n Extract foreground region '+str(regionID)+'...')
detectedRegion=labeledRegions==regionID
# compute bounding box and how much to enlarge bbox to consider wider context utilization (especially for patchify)
smallOverlappingPatches=patchify(img_WSI_prep.copy(),patch_size=(patchImgSize,patchImgSize,3),step=segmentationPatchStride)# CARE: IMAGE DATA AT THE RIGHT AND BOTTOM BORDERS IS LOST !!!