Image processing
This module contains operations commonly used in image processing.
- morphocut.image.ExtractROI(image: T | Variable[T], regionprops: T | Variable[T], alpha=0, bg_color=0)[source]
Extract part of an image using a
RegionPropertiesinstance.To be used in conjunction with
FindRegions.- Parameters:
image (np.ndarray or Variable) – Image from which regions are to be extracted.
regionprops (RegionProperties or Variable) –
RegionPropertiesinstance returned byFindRegions.alpha – 1=Background completely reset to bg_color; 0 = Background fully visible.
bg_color – Color for the background.
- morphocut.image.FindRegions(mask: T | Variable[T], image: T | Variable[T] = None, min_area=None, max_area=None, padding=0, warn_empty=False)[source]
Stream Find regions in a mask and calculate properties.
For more information see
skimage.measure.regionprops().Note
This Node creates multiple objects per incoming object.
- Parameters:
mask (np.ndarray or Variable) – Mask of a given image.
image (np.ndarray or Variable) – An image whose mask we have to find region with.
min_area (int) – Minimum area of the region. If the area of our prop/region is smaller than our min_area then it will discard it.
max_area (int) – Maximum area of the region. If the area of our prop/region is bigger than our max_area then it will discard it.
padding (int) – Size of the slices/regions of our image.
warn_empty (bool or str or Variable) – Warn for empty images (default false). If a String is supplied, it is used as an identifier for the image.
Example
mask = ... regionsprops = FindRegions(mask) # regionsprops: A skimage.measure.regionsprops object.
- morphocut.image.Gray2RGB(image: ndarray | Variable[ndarray], keep_dtype=False)[source]
Create an RGB representation of a gray-level image.
Note
Uses the skimage library
skimage.color.gray2rgb()to convert from Grayscale to RGB.- Parameters:
image (numpy.ndarray or Variable) – Gray-level input image.
- Returns:
Variable[numpy.ndarray] –
- The RGB image:
An array which is the same size as the input array, but with a channel dimension appended.
- morphocut.image.ImageProperties(mask: T | Variable[T], image: T | Variable[T] = None)[source]
Calculate region properties for an image containing a single object.
For more information see
skimage.measure.regionprops().- Parameters:
mask (np.ndarray or Variable) – Mask of a given image.
image (np.ndarray or Variable) – An image whose mask we have to find region with.
Example
image = ... mask = image < 128 regionsprops = ImageProperties(mask, image) # regionsprops: A skimage.measure.regionsprops object.
- morphocut.image.ImageReader(fp: T | Variable[T])[source]
Read and open the image from a given path.
Use Python Imaging Library PIL to open the file from a given path.
- Parameters:
fp (file or Variable) – A filename (string), pathlib.Path object or file object.
- morphocut.image.ImageStats(image: T | Variable[T], name: str = '')[source]
Parse information from a path
- morphocut.image.ImageWriter(fp: T | Variable[T], image: T | Variable[T], **kwargs)[source]
Write the image into the given directory path.
Use Python Imaging Library PIL to save the image in a given path.
- Parameters:
fp (file or Variable) – A filename (string), pathlib.Path object or file object.
image (np.ndarray or Variable) – Image that is to be saved into a given directory.
**kwargs – Arguments for
PIL.Image.Image.save().
- morphocut.image.RGB2Gray(image: ndarray | Variable[ndarray], keep_dtype=False)[source]
Compute luminance of an RGB image using
skimage.color.rgb2gray().- Parameters:
image (numpy.ndarray or Variable) – The image in RGB format.
- Returns:
Variable[numpy.ndarray] –
- The luminance image:
An array which is the same size as the input array, but with the channel dimension removed and dtype=float.
- class morphocut.image.RegionProperties(*args, **kwargs)[source]
Like skimage.measure.RegionProperties but without storing the whole image.
Please refer to skimage.measure.regionprops for more information on the available region properties.
- property image
Sliced binary region image which has the same size as bounding box.
- morphocut.image.RescaleIntensity(image: T | Variable[T], in_range: T | Variable[T] = 'image', dtype=None)[source]
Rescale the intensities of the image.
Note
Uses the skimage library
skimage.exposure.rescale_intensity().- Parameters:
image (np.ndarray or Variable) – An image file to be rescaled.
in_range ((str or 2-tuple) or Variable) – min/max as the intensity range.
dtype (str or Variable) – min/max of the image’s dtype as the intensity range.
- Returns:
Variable[np.ndarray] – Image with intensities rescaled.
- morphocut.image.ThresholdConst(image: T | Variable[T], threshold: T | Variable[T])[source]
Calculate a mask by applying a constant threshold.
The result will be image < threshold.
- Parameters:
image (np.ndarray or Variable) – Image for which the mask is to be calculated.
threshold (Number or Variable) – Threshold. Image intensities less than this will be True in the result.
- Returns:
Variable[np.ndarray] – Mask.