Pixelklassifizierung in Mehrkanal-Bildern#

APOC akzeptiert auch Listen von Bildern als Eingabe für Training und Vorhersage. Dies kann beispielsweise für die semantische Segmentierung in Mehrkanal-Bildern verwendet werden, die Zellkerne, Membranen und das dazwischenliegende Zytoplasma zeigen.

from skimage.data import cells3d
from skimage.io import imsave, imread
import napari
import numpy as np
import matplotlib.pyplot as plt
from pyclesperanto_prototype import imshow
image = cells3d()
image_ch1 = image[30, 0]
imshow(image_ch1)
../_images/7ec8e0d876b58ce19d48b9dd08489d1b06248bb0c63debf260a3d3fe297607b6.png
image_ch2 = image[30, 1]
imshow(image_ch2)
../_images/93ef221d87d0e2f6ad74bddf4f477d0c50e93d0ff2b71d57d86dcac811822655.png
filename = '../../data/cells_annotation.tif'
            
annotation = imread(filename)
fix, axs = plt.subplots(2,2, figsize=(10,10))

imshow(image_ch1, plot=axs[0,0], colormap="Greens_r")
imshow(image_ch2, plot=axs[0,1], colormap="Purples_r")
imshow(annotation, labels=True, plot=axs[1,0])
imshow(image_ch1, continue_drawing=True, plot=axs[1,1], colormap="Greens_r", alpha=0.5)
imshow(image_ch2, continue_drawing=True, plot=axs[1,1], colormap="Purples_r", alpha=0.5)
imshow(annotation, labels=True, plot=axs[1,1], alpha=0.5)
../_images/2a3a79a5abede0b40362db0e096093c1a9ca915f7db56798db995e647c38c988.png

Training#

from apoc import PixelClassifier

# define features
features = "sobel_of_gaussian_blur=2 laplace_box_of_gaussian_blur=2 gaussian_blur=2 sobel_of_gaussian_blur=4 laplace_box_of_gaussian_blur=4 gaussian_blur=4"

# this is where the model will be saved
cl_filename = 'test.cl'

clf = PixelClassifier(opencl_filename=cl_filename)
clf.train(features=features, ground_truth=annotation, image=[image_ch1, image_ch2])

Vorhersage#

result = clf.predict(image=[image_ch1, image_ch2])
imshow(result, labels=True)
../_images/689c857017b386314a1bbb59460fd511fd8db980b72036549f18ad1c77c81c68.png