Image dataο
Nanomesh has two classes for representing image data, Plane
for working
with 2D pixel data and Volume
for working with 3D voxel data.
These can be used to load, crop, transform, filter, and segment image data.
Both classes derive from Image
. Instantiating Image
will
create the appropriate subclass.
Classes
|
Generic image class. |
|
Data class for working with 2D image data. |
|
Data class for working with 3D (volumetric) image data.. |
Referenceο
- class nanomesh.Image(image: ndarray)[source]ο
Bases:
object
Generic image class.
Depending on the dimensions of the image data, the appropriate subclass will be chosen if possible.
- Parameters
image (numpy.array) β N-dimensional numpy array containing image data.
- imageο
The raw image data
- Type
Methods:
apply
(function,Β **kwargs)Apply function to
{classname}.image
array.astype
(dtype)Shortcut for
np.ndarray.astype()
.binary_digitize
([threshold])Convert into a binary image.
digitize
(bins,Β **kwargs)Digitize image.
fft
()Apply fourier transform to image.
from_sitk_image
(sitk_image)Return instance from
SimpleITK.Image
.gaussian
([sigma])Apply Gaussian blur to image.
Invert the contrast of the image.
load
(filename,Β **kwargs)Load the data.
Rescale values to 0.0 to 1.0.
save
(filename)Save the data.
threshold
([method])Compute threshold value using given method.
Return instance of
SimpleITK.Image
from{classname}.image()
.- apply(function: Callable, **kwargs)[source]ο
Apply function to
{classname}.image
array. Return an instance of{classname}
if the result is of the same dimensions, otherwise return the result of the operation.- Parameters
function (callable) β Function to apply to
{classname}.image
.**kwargs β Keyword arguments to pass to function.
- Returns
New instance of
{classname}
.- Return type
{classname}
- binary_digitize(threshold: Optional[Union[float, str]] = None)[source]ο
Convert into a binary image.
- Parameters
threshold (float, optional) β Threshold used for segmentation. If given as a string, apply corresponding theshold via
{classname}.threshold()
. Defaults to median.- Returns
New instance of
{classname}
.- Return type
{classname}
- digitize(bins: Union[list, tuple], **kwargs)[source]ο
Digitize image.
For more info see
numpy.digitize()
.- Parameters
bins (list, tuple) β List of bin values. Must be monotonic and one-dimensional.
**kwargs β These parameters are passed to
numpy.digitize()
.
- Returns
New instance of
{classname}
.- Return type
{classname}
- fft() Image [source]ο
Apply fourier transform to image.
- Returns
Real component of fourier transform with the zero-frequency component shifted to the center of the spectrum.
- Return type
{classname}
- gaussian(sigma: int = 1, **kwargs)[source]ο
Apply Gaussian blur to image.
- Parameters
sigma (int) β Standard deviation for Gaussian kernel.
**kwargs β These parameters are passed to
skimage.filters.gaussian()
.
- Returns
New instance of
{classname}
.- Return type
{classname}
- invert_contrast()[source]ο
Invert the contrast of the image.
- Returns
out β Inverted image
- Return type
{classname}
- classmethod load(filename: PathLike, **kwargs) Image [source]ο
Load the data. Supported filetypes: .npy, .vol.
- For memory mapping, use mmap_mode=βrβ. Memory-mapped
files are used for accessing small segments of large files on disk, without reading the entire file into memory. Note that this can still result in some slow / unexpected behaviour with some operations.
More info:
numpy.memmap()
- Parameters
filename (PathLike) β Name of the file to load.
**kwargs β These parameters are passed on to data readers.
- Returns
Instance of
{classname}
.- Return type
{classname}
- Raises
IOError β Raised if the file extension is unknown.
- normalize_values()[source]ο
Rescale values to 0.0 to 1.0.
- Returns
out β Normalized image
- Return type
{classname}
- save(filename: PathLike)[source]ο
Save the data. Supported filetypes: .npy.
- Parameters
filename (Pathlike) β Name of the file to save to.
- threshold(method: str = 'otsu', **kwargs) float [source]ο
Compute threshold value using given method.
For more info, see
skimage.filters
- class nanomesh.Plane(image: ndarray)[source]ο
Bases:
Image
Data class for working with 2D image data.
Depending on the dimensions of the image data, the appropriate subclass will be chosen if possible.
- Parameters
image ((i,j) numpy.array) β N-dimensional numpy array containing image data.
- imageο
The raw image data
- Type
(i,j) numpy.ndarray
Methods:
apply
(function,Β **kwargs)Apply function to
Plane.image
array.astype
(dtype)Shortcut for
np.ndarray.astype()
.binary_digitize
([threshold])Convert into a binary image.
clear_border
(*,Β object_label,Β fill_val,Β **kwargs)Remove objects at the border of the image.
compare_with_digitized
(digitized[,Β cmap])Compare image with digitized (segmented) image.
compare_with_mesh
(mesh)Make a plot comparing the image with the given mesh.
compare_with_other
(other[,Β cmap])Compare image with other image.
crop
(left,Β top,Β right,Β bottom)Crop image to pixel indices.
crop_to_roi
(bbox)Crop plane to rectangle defined by bounding box.
digitize
(bins,Β **kwargs)Digitize image.
fft
()Apply fourier transform to image.
from_sitk_image
(sitk_image)Return instance from
SimpleITK.Image
.gaussian
([sigma])Apply Gaussian blur to image.
generate_mesh
(**kwargs)Generate mesh from binary (segmented) image.
Invert the contrast of the image.
load
(**kwargs)Load the data.
Rescale values to 0.0 to 1.0.
plot
(*args,Β **kwargs)Plot the image using
matplotlib
.save
(filename)Save the data.
select_roi
([from_points])Select region of interest in interactive matplotlib figure.
show
(*[,Β ax,Β title])Plot the image using
matplotlib
.threshold
([method])Compute threshold value using given method.
Return instance of
SimpleITK.Image
fromPlane.image()
.try_all_threshold
(**kwargs)Produce a plot trying all available thresholds using
skimage.filters.try_all_threshold()
.- apply(function: Callable, **kwargs)ο
Apply function to
Plane.image
array. Return an instance ofPlane
if the result is of the same dimensions, otherwise return the result of the operation.- Parameters
function (callable) β Function to apply to
Plane.image
.**kwargs β Keyword arguments to pass to function.
- Returns
New instance of
Plane
.- Return type
- binary_digitize(threshold: Optional[Union[float, str]] = None)ο
Convert into a binary image.
- Parameters
threshold (float, optional) β Threshold used for segmentation. If given as a string, apply corresponding theshold via
Plane.threshold()
. Defaults to median.- Returns
New instance of
Plane
.- Return type
- clear_border(*, object_label: int, fill_val: int, **kwargs) Plane [source]ο
Remove objects at the border of the image.
- Parameters
object_label (int) β Label of the objects to remove.
fill_val (int) β Cleared objects are set to this value.
**kwargs β These parameters are passed to
skimage.segmentation.clear_border()
.
- Returns
New instance of
Plane
.- Return type
- compare_with_digitized(digitized: Union[ndarray, Plane], cmap: Optional[str] = None, **kwargs) plt.Axes [source]ο
Compare image with digitized (segmented) image. Returns a plot with the overlay of the digitized image.
- Parameters
digitized (numpy.ndarray, Plane) β Digitized image of the same dimensions to overlay
cmap (str) β Matplotlib color map for
matplotlib.pyplot.imshow()
**kwargs β These parameters are passed to
skimage.color.label2rgb()
.
- Returns
ax
- Return type
- compare_with_mesh(mesh: TriangleMesh) plt.Axes [source]ο
Make a plot comparing the image with the given mesh.
- Parameters
mesh (TriangleMesh) β Mesh to compare the image with.
- Return type
plt.Axes
- compare_with_other(other: Union[ndarray, Plane], cmap: Optional[str] = None, **kwargs) plt.Axes [source]ο
Compare image with other image.
- Parameters
other (numpy.ndarray, Plane) β Other image of the same dimensions to overlay
cmap (str) β Matplotlib color map for
matplotlib.pyplot.imshow()
**kwargs β These parameters are passed to
skimage.util.compare_images()
.
- Returns
ax
- Return type
- crop_to_roi(bbox: ndarray) Plane [source]ο
Crop plane to rectangle defined by bounding box.
- Parameters
bbox ((4,2) numpy.ndarray) β List of points describing region of interest. The bounding box may be rotated.
- Returns
Cropped region as
Plane
object.- Return type
- digitize(bins: Union[list, tuple], **kwargs)ο
Digitize image.
For more info see
numpy.digitize()
.- Parameters
bins (list, tuple) β List of bin values. Must be monotonic and one-dimensional.
**kwargs β These parameters are passed to
numpy.digitize()
.
- Returns
New instance of
Plane
.- Return type
- fft() Image ο
Apply fourier transform to image.
- Returns
Real component of fourier transform with the zero-frequency component shifted to the center of the spectrum.
- Return type
- gaussian(sigma: int = 1, **kwargs)ο
Apply Gaussian blur to image.
- Parameters
sigma (int) β Standard deviation for Gaussian kernel.
**kwargs β These parameters are passed to
skimage.filters.gaussian()
.
- Returns
New instance of
Plane
.- Return type
- generate_mesh(**kwargs) TriangleMesh [source]ο
Generate mesh from binary (segmented) image.
- Parameters
**kwargs β Keyword arguments are passed to
nanomesh.plane2mesh()
- Returns
mesh β Description of the mesh.
- Return type
- invert_contrast()ο
Invert the contrast of the image.
- Returns
out β Inverted image
- Return type
- classmethod load(**kwargs) Image ο
Load the data. Supported filetypes: .npy, .vol.
- For memory mapping, use mmap_mode=βrβ. Memory-mapped
files are used for accessing small segments of large files on disk, without reading the entire file into memory. Note that this can still result in some slow / unexpected behaviour with some operations.
More info:
numpy.memmap()
- normalize_values()ο
Rescale values to 0.0 to 1.0.
- Returns
out β Normalized image
- Return type
- plot(*args, **kwargs)[source]ο
Plot the image using
matplotlib
.- Parameters
ax (matplotlib.axes.Axes, optional) β Axes to use for plotting.
title (str, optional) β Title for the plot.
**kwargs β These parameters are passed to
matplotlib.pyplot.imshow()
.
- Returns
ax β Instance of
matplotlib.axes.Axes
- Return type
- save(filename: PathLike)ο
Save the data. Supported filetypes: .npy.
- Parameters
filename (Pathlike) β Name of the file to save to.
- select_roi(from_points: Optional[ndarray] = None)[source]ο
Select region of interest in interactive matplotlib figure.
- Parameters
from_points ((n, 2) numpy.ndarray, optional) β List of points that are used as anchors for the roi selection.
- Returns
roi β Region of interest object. Bounding box is stored in
roi.bbox
.- Return type
nanomesh.image._roi2d.ROISelector
- show(*, ax: Optional[Axes] = None, title: Optional[str] = None, **kwargs) plt.Axes [source]ο
Plot the image using
matplotlib
.- Parameters
ax (matplotlib.axes.Axes, optional) β Axes to use for plotting.
title (str, optional) β Title for the plot.
**kwargs β These parameters are passed to
matplotlib.pyplot.imshow()
.
- Returns
ax β Instance of
matplotlib.axes.Axes
- Return type
- threshold(method: str = 'otsu', **kwargs) float ο
Compute threshold value using given method.
For more info, see
skimage.filters
- to_sitk_image()ο
Return instance of
SimpleITK.Image
fromPlane.image()
.
- try_all_threshold(**kwargs)[source]ο
Produce a plot trying all available thresholds using
skimage.filters.try_all_threshold()
.- Parameters
**kwargs β These parameters are passed to
skimage.filters.try_all_threshold()
.
- class nanomesh.Volume(image: ndarray)[source]ο
Bases:
Image
Data class for working with 3D (volumetric) image data..
Depending on the dimensions of the image data, the appropriate subclass will be chosen if possible.
- Parameters
image ((i,j,k) numpy.array) β N-dimensional numpy array containing image data.
- imageο
The raw image data
- Type
(i,j,k) numpy.ndarray
Methods:
apply
(function,Β **kwargs)Apply function to
Volume.image
array.astype
(dtype)Shortcut for
np.ndarray.astype()
.binary_digitize
([threshold])Convert into a binary image.
digitize
(bins,Β **kwargs)Digitize image.
fft
()Apply fourier transform to image.
from_sitk_image
(sitk_image)Return instance from
SimpleITK.Image
.gaussian
([sigma])Apply Gaussian blur to image.
generate_mesh
(**kwargs)Generate mesh from binary (segmented) image.
Invert the contrast of the image.
load
(**kwargs)Load the data.
Rescale values to 0.0 to 1.0.
plot
(*args,Β **kwargs)Shortcut for
Volume.show()
.save
(filename)Save the data.
select_plane
([x,Β y,Β z])Select a slice in the volume.
select_subvolume
(*[,Β xs,Β ys,Β zs])Select a subvolume from the current volume.
show
([renderer])Show volume using itkwidgets or ipyvolume.
show_slice
(**kwargs)Show slice using
nanomesh.image.SliceViewer
.threshold
([method])Compute threshold value using given method.
Return instance of
SimpleITK.Image
fromVolume.image()
.- apply(function: Callable, **kwargs)ο
Apply function to
Volume.image
array. Return an instance ofVolume
if the result is of the same dimensions, otherwise return the result of the operation.- Parameters
function (callable) β Function to apply to
Volume.image
.**kwargs β Keyword arguments to pass to function.
- Returns
New instance of
Volume
.- Return type
- binary_digitize(threshold: Optional[Union[float, str]] = None)ο
Convert into a binary image.
- Parameters
threshold (float, optional) β Threshold used for segmentation. If given as a string, apply corresponding theshold via
Volume.threshold()
. Defaults to median.- Returns
New instance of
Volume
.- Return type
- digitize(bins: Union[list, tuple], **kwargs)ο
Digitize image.
For more info see
numpy.digitize()
.- Parameters
bins (list, tuple) β List of bin values. Must be monotonic and one-dimensional.
**kwargs β These parameters are passed to
numpy.digitize()
.
- Returns
New instance of
Volume
.- Return type
- fft() Image ο
Apply fourier transform to image.
- Returns
Real component of fourier transform with the zero-frequency component shifted to the center of the spectrum.
- Return type
- gaussian(sigma: int = 1, **kwargs)ο
Apply Gaussian blur to image.
- Parameters
sigma (int) β Standard deviation for Gaussian kernel.
**kwargs β These parameters are passed to
skimage.filters.gaussian()
.
- Returns
New instance of
Volume
.- Return type
- generate_mesh(**kwargs) MeshContainer [source]ο
Generate mesh from binary (segmented) image.
- Parameters
**kwargs β These parameters are passed to mesh3d.volume2mesh
- Returns
Instance of
MeshContainer
- Return type
- invert_contrast()ο
Invert the contrast of the image.
- Returns
out β Inverted image
- Return type
- classmethod load(**kwargs) Image ο
Load the data. Supported filetypes: .npy, .vol.
- For memory mapping, use mmap_mode=βrβ. Memory-mapped
files are used for accessing small segments of large files on disk, without reading the entire file into memory. Note that this can still result in some slow / unexpected behaviour with some operations.
More info:
numpy.memmap()
- normalize_values()ο
Rescale values to 0.0 to 1.0.
- Returns
out β Normalized image
- Return type
- plot(*args, **kwargs)[source]ο
Shortcut for
Volume.show()
.
- save(filename: PathLike)ο
Save the data. Supported filetypes: .npy.
- Parameters
filename (Pathlike) β Name of the file to save to.
- select_plane(x: Optional[int] = None, y: Optional[int] = None, z: Optional[int] = None) Plane [source]ο
Select a slice in the volume. Either x, y or z must be specified.
- select_subvolume(*, xs: Optional[tuple] = None, ys: Optional[tuple] = None, zs: Optional[tuple] = None) Volume [source]ο
Select a subvolume from the current volume.
Each range must include a start and stop value, for example:
vol.select_subvolume(xs=(10, 20)) is equivalent to: vol.image[[:,:,10:20]
or
vol.select_subvolume(ys=(20, 25), zs=(40, 50)) is equivalent to: vol.image[[40:50,20:25,:]
- show(renderer: str = 'itkwidgets', **kwargs) None [source]ο
Show volume using itkwidgets or ipyvolume.
- Parameters
renderer (str, optional) β Select renderer (ipvolume, itkwidgets)
**kwargs β These parameters are passed to
itkwidgets.view()
oripyvolume.quickvolshow()
.
- Raises
ValueError β Raised if the renderer is unknown.
- show_slice(**kwargs)[source]ο
Show slice using
nanomesh.image.SliceViewer
.Extra arguments are passed on.
- Parameters
**kwargs β These parameters are passed to
nanomesh.image.SliceViewer
- Return type
- threshold(method: str = 'otsu', **kwargs) float ο
Compute threshold value using given method.
For more info, see
skimage.filters
- to_sitk_image()ο
Return instance of
SimpleITK.Image
fromVolume.image()
.