Quick start guideΒΆ
Here we illustrate the use of jicbioimage
to segment an image of Greek
coins from Pompeii.
First we load the image from scikit-image as a numpy array.
>>> import skimage.data
>>> array = skimage.data.coins()
We then create a jicbioimage.core.image.Image
instance from the array.
>>> from jicbioimage.core.image import Image
>>> image = Image.from_array(array)
If using IPython qtconsole/notebook the image can be viewed directly in the interpreter.
>>> image

We can now threshold the image, for example using Otsu’s method.
>>> from jicbioimage.transform import threshold_otsu
>>> image = threshold_otsu(image)
>>> image

Let us segment the thresholded image into connected components.
>>> from jicbioimage.segment import connected_components
>>> segmentation = connected_components(image, background=0)
>>> segmentation

The jicbioimage.segment.connected_components()
function returns an instance of
the jicbioimage.segment.SegmentedImage
class, which provides access to
segmented regions of interest as jicbioimage.segment.Region
instances.
Finally, let us write a couple of functions to create an augmented reality image.
>>> import numpy as np
>>> from jicbioimage.illustrate import AnnotatedImage
>>> def text_position(region):
... "Return x, y coordinates of text position."
... ys, xs = region.index_arrays
... y = np.min(ys) - 5
... x = np.mean(xs, dtype=int)
... return (y, x)
...
>>> def augment_image(image, segmentation):
... "Return an augmented image."
... augmented = AnnotatedImage.from_grayscale(image)
... for i in segmentation.identifiers:
... region = segmentation.region_by_identifier(i)
... if region.area > 300 and region.area < 5000:
... augmented.mask_region(region.convex_hull.border)
... pos = text_position(region.convex_hull)
... text = "{}px".format(region.convex_hull.area)
... augmented.text_at(text, pos, center=True, antialias=False)
... return augmented
...
>>> augmented = augment_image(array, segmentation)
>>> augmented
