root_path = Path.cwd().parentPath('/home/hasan/workspace/git_data/fine_tune_SAM')
dataset will be patched here from whole side images
Training and test image and mask can be downloaded from the following command - curl https://documents.epfl.ch/groups/c/cv/cvlab-unit/www/data/%20ElectronMicroscopy_Hippocampus/training_groundtruth.tif > mask_name.tif - curl https://documents.epfl.ch/groups/c/cv/cvlab-unit/www/data/%20ElectronMicroscopy_Hippocampus/training.tif> train_images.tif - curl https://documents.epfl.ch/groups/c/cv/cvlab-unit/www/data/%20ElectronMicroscopy_Hippocampus/testing_groundtruth.tif> test_mask.tif - curl https://documents.epfl.ch/groups/c/cv/cvlab-unit/www/data/%20ElectronMicroscopy_Hippocampus/testing.tif> test_images.tif
big_img_tst = tifffile.imread(test_imgs)
big_msk_tst = tifffile.imread(test_masks)
print(f' image tif has a shape and mask tif has a shape of {big_img_tst.shape} and {big_msk_tst.shape} respectively') image tif has a shape and mask tif has a shape of (165, 768, 1024) and (165, 768, 1024) respectively
show_rand_img (idx:int, im_path:str, msk_path:str)
Show random mask and image from together from path
| Type | Details | |
|---|---|---|
| idx | int | in case of None, a random image is chosen |
| im_path | str | |
| msk_path | str |
Notebook is here
patch size and step size and it will created the patches with same name of the images, ony another index will be created to tell which patch number is thatfor i in tqdm(range(len(big_img_tst))):
cv2.imwrite(f'{actual_im_path_tst}/img_{i}.png', big_img_tst[i])
cv2.imwrite(f'{actual_msk_path_tst}/img_{i}.png', big_msk_tst[i])100%|██████████| 165/165 [00:02<00:00, 60.49it/s]
(#165) [Path('/home/hasan/workspace/data/microscopy_data/test_images/img_51.png'),Path('/home/hasan/workspace/data/microscopy_data/test_images/img_98.png'),Path('/home/hasan/workspace/data/microscopy_data/test_images/img_133.png'),Path('/home/hasan/workspace/data/microscopy_data/test_images/img_107.png'),Path('/home/hasan/workspace/data/microscopy_data/test_images/img_16.png'),Path('/home/hasan/workspace/data/microscopy_data/test_images/img_150.png'),Path('/home/hasan/workspace/data/microscopy_data/test_images/img_158.png'),Path('/home/hasan/workspace/data/microscopy_data/test_images/img_145.png'),Path('/home/hasan/workspace/data/microscopy_data/test_images/img_48.png'),Path('/home/hasan/workspace/data/microscopy_data/test_images/img_40.png')...]
patch_img_and_mask (im_path:Union[pathlib.Path,str], msk_path:Union[pathlib.Path,str], patch_im_path:Union[pathlib.Path,str], patch_msk_path:Union[pathlib.Path,str], PATCH_SIZE:int=256, STEP:int=256)
Create patch images and masks from original images and masks
for i in tqdm(patch_msk_path_tst.ls()):
name_ = Path(i).name
img = cv2.imread(i.as_posix(), cv2.IMREAD_GRAYSCALE)
if not img.max() > 0:
i.unlink()
im_ = Path(f'{patch_img_path_tst}/{name_}')
im_.unlink()100%|██████████| 1980/1980 [00:00<00:00, 2423.80it/s]
for i in tqdm(patch_msk_path.ls()):
name_ = Path(i).name
img = cv2.imread(i.as_posix(), cv2.IMREAD_GRAYSCALE)
if not img.max() > 0:
i.unlink()
im_ = Path(f'{patch_img_path}/{name_}')
im_.unlink()100%|██████████| 1980/1980 [00:00<00:00, 2697.89it/s]