import pyclesperanto_prototype as cle
from skimage.data import cells3d
import matplotlib.pyplot as plt
from skimage.morphology import closing, disk
from skimage.io import imsave
image = cells3d()
membrane2d = cle.push(image[30,0])
cle.imshow(membrane2d)
labels = cle.label(cle.gaussian_blur(membrane2d, sigma_x=2, sigma_y=2) < 2000)
cle.imshow(labels, labels=True)
for i, r in enumerate(range(0, 24, 3)):
fix, axs = plt.subplots(1,3, figsize=(10,10))
cle.imshow(cle.closing_labels(labels, radius=r), plot=axs[0], labels=True)
cle.imshow(labels, plot=axs[1], labels=True)
cle.imshow(cle.opening_labels(labels, radius=r), plot=axs[2], labels=True)
axs[0].set_title("Closed labels (r=" + str(r) + ")")
axs[1].set_title("Original labels")
axs[2].set_title("Opened labels (r=" + str(r) + ")")
r = 5
fix, axs = plt.subplots(1,3, figsize=(10,10))
cle.imshow(labels, plot=axs[0], labels=True)
cle.imshow(cle.closing_labels(labels, radius=r), plot=axs[1], labels=True)
cle.imshow(cle.closing_sphere(labels != 0, radius_x=r, radius_y=r), plot=axs[2], color_map="Greys_r")
axs[0].set_title("Original labels")
axs[1].set_title("Closed labels (r=" + str(r) + ")")
axs[2].set_title("Binary closing (r=" + str(r) + ")")
c:\structure\code\pyclesperanto_prototype\pyclesperanto_prototype\_tier9\_imshow.py:46: UserWarning: The imshow parameter color_map is deprecated. Use colormap instead. warnings.warn("The imshow parameter color_map is deprecated. Use colormap instead.")
Text(0.5, 1.0, 'Binary closing (r=5)')
r = 24
fix, axs = plt.subplots(1,3, figsize=(10,10))
cle.imshow(labels, plot=axs[0], labels=True)
cle.imshow(cle.closing_labels(labels, radius=r), plot=axs[1], labels=True)
cle.imshow(cle.closing_sphere(labels, radius_x=r, radius_y=r), plot=axs[2], labels=True)
axs[0].set_title("Original labels")
axs[1].set_title("Closed labels (r=" + str(r) + ")")
axs[2].set_title("Binary closing (r=" + str(r) + ")")
Text(0.5, 1.0, 'Binary closing (r=24)')
def naive_closing_labels(labels, radius):
temp = cle.dilate_labels(labels, radius=radius)
return cle.erode_labels(temp, radius=radius)
r = 12
fix, axs = plt.subplots(1,3, figsize=(10,10))
cle.imshow(labels, plot=axs[0], labels=True)
cle.imshow(cle.closing_labels(labels, radius=r), plot=axs[1], labels=True)
cle.imshow(naive_closing_labels(labels, radius=r), plot=axs[2], labels=True)
axs[0].set_title("Original labels")
axs[1].set_title("Closed labels (r=" + str(r) + ")")
axs[2].set_title("Dilation + erosion (r=" + str(r) + ")")
Text(0.5, 1.0, 'Dilation + erosion (r=12)')
The following code was used to produce the video shown in this tweet
for i, r in enumerate(list(range(0, 24, 1)) + list(range(24, 0, -1))):
fix, axs = plt.subplots(1,3, figsize=(10,10))
cle.imshow(cle.closing_labels(labels, radius=r), plot=axs[0], labels=True)
cle.imshow(labels, plot=axs[1], labels=True)
cle.imshow(cle.opening_labels(labels, radius=r), plot=axs[2], labels=True)
axs[0].set_title("Closed labels (r=" + str(r) + ")")
axs[1].set_title("Original labels")
axs[2].set_title("Opened labels (r=" + str(r) + ")")
#plt.savefig("temp/%02d" % (i,) + ".png")
C:\Users\rober\AppData\Local\Temp\ipykernel_9796\2910083520.py:3: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`). fix, axs = plt.subplots(1,3, figsize=(10,10))