Skip to content
Snippets Groups Projects

Implementation of Deep Learning unit tests, as well as paths to the 2d data for windows users in the UNet jupyter notebook.

Files

+ 96
0
 
%% Cell type:markdown id: tags:
 
# Image annotation tool
 
This notebook shows how the annotation interface can be used to create masks for images
 
%% Cell type:code id: tags:
 
``` python
 
import qim3d
 
import matplotlib.pyplot as plt
 
import matplotlib as mpl
 
import numpy as np
 
%matplotlib inline
 
%% Cell type:code id: tags:
 
``` python
 
# Load 2D example image
 
img = qim3d.examples.blobs_256x256
 
 
# Display image
 
plt.imshow(img)
 
plt.show()
 
%% Cell type:code id: tags:
 
``` python
 
# Start annotation tool
 
interface = qim3d.gui.annotation_tool.Interface()
 
interface.max_masks = 4
 
 
# We can directly pass the image we loaded to the interface
 
interface.launch(img=img)
 
%% Cell type:code id: tags:
 
``` python
 
# When 'prepare mask for download' is pressed once, the mask can be retrieved with the get_result() method
 
mask = interface.get_result()
 
%% Cell type:markdown id: tags:
 
## Check the obtained mask
 
%% Cell type:code id: tags:
 
``` python
 
print (f"Original image shape..: {img.shape}")
 
print (f"Mask image shape......: {mask.shape}")
 
print (f"\nNumber of masks: {np.max(mask)}")
 
%% Cell type:markdown id: tags:
 
## Show the masked regions
 
%% Cell type:code id: tags:
 
``` python
 
%matplotlib inline
 
 
nmasks = np.max(mask)
 
fig, axs = plt.subplots(nrows=1, ncols=nmasks+2, figsize=(12,3))
 
 
# Show original image
 
axs[0].imshow(img)
 
axs[0].set_title("Original")
 
axs[0].axis('off')
 
 
 
# Show masks
 
cmap = mpl.colormaps["rainbow"].copy()
 
cmap.set_under(color='black') # Sets the background to black
 
axs[1].imshow(mask, interpolation='none', cmap=cmap, vmin=1, vmax=nmasks+1)
 
axs[1].set_title("Masks")
 
axs[1].axis('off')
 
 
# Show masked regions
 
for idx in np.arange(2, nmasks+2):
 
mask_id = idx-1
 
submask = mask.copy()
 
submask[submask != mask_id] = 0
 
 
masked_img = img.copy()
 
masked_img[submask==0] = 0
 
axs[idx].imshow(masked_img)
 
axs[idx].set_title(f"Mask {mask_id}")
 
 
axs[idx].axis('off')
 
 
plt.show()
Loading