Vizailization will be created here

Viz notebook

The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload
mpl.rcParams['image.cmap'] = 'gray'
Path.home()
Path('/home/hasan')
im_path = Path(r'/home/hasan/Schreibtisch/projects/data/microscopy/patch_train_images/')
mask_path = Path(r'/home/hasan/Schreibtisch/projects/data/microscopy/patch_train_masks/')
#im_path = Path(r'/home/hasan/workspace/data/microscopy_data/patch_images/')
#mask_path = Path(r'/home/hasan/workspace/data/microscopy_data/patch_masks')

images=im_path.ls()
masks=mask_path.ls()
r_idx = np.random.choice(len(im_path.ls()), 1)[0]
s_img = images[r_idx]
s_msk = masks[r_idx]
s_img.name, s_msk.name
('img_21_p_3.png', 'img_21_p_3.png')
sn_msk_img = cv2.imread(str(s_msk), cv2.IMREAD_GRAYSCALE)
np.unique(sn_msk_img)
array([  0, 255], dtype=uint8)

source

overlay_mask

 overlay_mask (im_path, msk_path, overlay_clr=(0, 1, 0), scale=1,
               alpha=0.5)

Creaete a overlay image from image and mask

overlay_mask(s_img, s_msk,alpha=0.1)


source

overlay_mask_border_on_image

 overlay_mask_border_on_image (im_path, msk_path, border_color=(0, 1, 0),
                               border_width=1)

*Overlays the border of a binary mask on a grayscale image and displays the result using matplotlib.

Args: image (numpy.ndarray): Grayscale image. mask (numpy.ndarray): Binary mask of the same size as the image. border_color (tuple): RGB color for the mask border in the range [0, 1]. border_width (int): Width of the border.

Returns: None: The function displays a plot.*

overlay_mask_border_on_image(s_img, s_msk)

#yolo_mask_path = Path(r'/home/hasan/workspace/data/microscopy_data/yolo_dataset_train')
#im_path = Path(r'/home/hasan/workspace/data/microscopy_data/patch_images/')
yolo_mask_path = Path(r'/home/hasan/Schreibtisch/projects/data/microscopy/yolo_dataset_train')
im_path = Path(r'/home/hasan/Schreibtisch/projects/data/microscopy/patch_train_images/')
yolo_mask_path.ls(), im_path.ls()
((#1633) [Path('/home/hasan/Schreibtisch/projects/data/microscopy/yolo_dataset_train/img_139_p_11.txt'),Path('/home/hasan/Schreibtisch/projects/data/microscopy/yolo_dataset_train/img_48_p_0.txt'),Path('/home/hasan/Schreibtisch/projects/data/microscopy/yolo_dataset_train/img_120_p_1.txt'),Path('/home/hasan/Schreibtisch/projects/data/microscopy/yolo_dataset_train/img_54_p_9.txt'),Path('/home/hasan/Schreibtisch/projects/data/microscopy/yolo_dataset_train/img_2_p_2.txt'),Path('/home/hasan/Schreibtisch/projects/data/microscopy/yolo_dataset_train/img_34_p_10.txt'),Path('/home/hasan/Schreibtisch/projects/data/microscopy/yolo_dataset_train/img_50_p_1.txt'),Path('/home/hasan/Schreibtisch/projects/data/microscopy/yolo_dataset_train/img_42_p_8.txt'),Path('/home/hasan/Schreibtisch/projects/data/microscopy/yolo_dataset_train/img_67_p_1.txt'),Path('/home/hasan/Schreibtisch/projects/data/microscopy/yolo_dataset_train/img_20_p_1.txt')...],
 (#1642) [Path('/home/hasan/Schreibtisch/projects/data/microscopy/patch_train_images/img_162_p_9.png'),Path('/home/hasan/Schreibtisch/projects/data/microscopy/patch_train_images/img_11_p_9.png'),Path('/home/hasan/Schreibtisch/projects/data/microscopy/patch_train_images/img_70_p_5.png'),Path('/home/hasan/Schreibtisch/projects/data/microscopy/patch_train_images/img_67_p_1.png'),Path('/home/hasan/Schreibtisch/projects/data/microscopy/patch_train_images/img_74_p_9.png'),Path('/home/hasan/Schreibtisch/projects/data/microscopy/patch_train_images/img_16_p_5.png'),Path('/home/hasan/Schreibtisch/projects/data/microscopy/patch_train_images/img_23_p_1.png'),Path('/home/hasan/Schreibtisch/projects/data/microscopy/patch_train_images/img_112_p_6.png'),Path('/home/hasan/Schreibtisch/projects/data/microscopy/patch_train_images/img_121_p_11.png'),Path('/home/hasan/Schreibtisch/projects/data/microscopy/patch_train_images/img_152_p_1.png')...])
r_idx = np.random.choice(len(im_path.ls()), 1)[0]
print(f'random index: {r_idx}')
random index: 546
yolo_mask_path.ls()[r_idx], im_path.ls()[r_idx]
(Path('/home/hasan/Schreibtisch/projects/data/microscopy/yolo_dataset_train/img_27_p_0.txt'),
 Path('/home/hasan/Schreibtisch/projects/data/microscopy/patch_train_images/img_73_p_6.png'))

source

overlay_yolo_mask

 overlay_yolo_mask (im_path, msk_path, color=None, idx=None, im_name=None,
                    fill=False, alpha=0.3)

Creaete a overlay image from image and mask

Type Default Details
im_path
msk_path
color NoneType None color values other matplotlib colors
idx NoneType None Index of image in the folder other random will be chosen
im_name NoneType None Imge name with extension
fill bool False whther to fill the mask or not
alpha float 0.3 alpha value for the mask for transparency
overlay_yolo_mask(im_path, msk_path=yolo_mask_path, color='red', fill=False)