The crop
widget allows cropping a 2D or 3D image.
import stackview
from skimage.io import imread
import numpy as np
image = imread("data/CalibZAPWfixed_000154_max.tif")
The widget contains 2 or 3 sliders, for 2D and 3D images respectively. It also supports stackview
's typical parameters such as continuous_update
, zoom_factor
, etc.
image_2d = image[0]
crop_widget_2d = stackview.crop(image_2d, continuous_update=True)
crop_widget_2d
_Cropper(children=(IntRangeSlider(value=(0, 235), description='Y', max=235), IntRangeSlider(value=(0, 389), de…
crop_widget = stackview.crop(image,
continuous_update=True,
zoom_factor=0.75)
crop_widget
_Cropper(children=(IntRangeSlider(value=(0, 100), description='Z'), IntRangeSlider(value=(0, 235), description…
You can also modify the labels of the axes. E.g. in the use-case shown here, we're modifying timelapse dataset.
crop_widget = stackview.crop(image,
continuous_update=True,
zoom_factor=0.75,
slider_text="Frame",
axis_names=["Frame", "Y", "X"])
crop_widget
_Cropper(children=(IntRangeSlider(value=(0, 100), description='Frame'), IntRangeSlider(value=(0, 235), descrip…
You can change the range sliders programmatically.
crop_widget = stackview.crop(image, continuous_update=True, zoom_factor=2)
crop_widget.range = (slice(0, 40), slice(40, 80), slice(80, 120))
crop_widget
_Cropper(children=(IntRangeSlider(value=(0, 40), description='Z'), IntRangeSlider(value=(40, 80), description=…
You can retrieve the cropped range like this.
r = crop_widget.range
r
(slice(0, 40, 1), slice(40, 80, 1), slice(80, 120, 1))
It technically is a tuple of Python slice
s.
r[0].start, r[0].stop
(0, 40)
You can use this range to crop the image...
r = crop_widget.range
image[r].shape
(40, 40, 40)
... or retrieve the cropped image directly.
cropped_image = crop_widget.crop()
cropped_image.shape
(40, 40, 40)
This cropped_image
object uses stackview
's insight
under the hood and thus, comes with a nice view.
cropped_image
|
|
crop_widget = stackview.crop(image,
continuous_update=True,
zoom_factor=0.75)
crop_widget
_Cropper(children=(IntRangeSlider(value=(0, 100), description='Z'), IntRangeSlider(value=(0, 235), description…
crop_widget.range
(slice(0, 100, 1), slice(0, 235, 1), slice(0, 389, 1))