Working with images¶
There are several types of images in the
Raw data is contained in the
jicbioimage.core.image.Image class. The
jicbioimage.core.image.MicroscopyImage classes contain image meta data
along with a reference to the raw image.
jicbioimage.core.image.Image is a subclass of
In addition to the
numpy.ndarray functionality the
jicbioimage.core.image.Image class has specialised functionality for
creating images, tracking the history of images and returning png/html
representations of images.
numpy to create images¶
There are several ways of creating images. One can use the
functionality inherited from
>>> from jicbioimage.core.image import Image >>> Image((50,50)) <Image object at 0x..., dtype=uint8>
When creating an image in this fashion it will be filled with the noise of whatever was present in that piece of computer memory before the memory was allocated to the image.
A safer way to create an image is to first create a
numpy.ones() and then cast it to the
>>> import numpy as np >>> np.zeros((50,50), dtype=np.uint8).view(Image) <Image object at 0x..., dtype=uint8>
When creating an array in this fashion it’s history creation attribute is empty.
>>> print(np.zeros((50, 50), dtype=np.uint8).view(Image).history.creation) None
To assign a creation event to the image history one can use the
jicbioimage.core.image.Image.from_array() class method.
>>> ar = np.zeros((50, 50), dtype=np.uint8) >>> im = Image.from_array(ar) >>> im.history.creation 'Created Image from array'
Accessing png representations of an image¶
jicbioimage.core.image.Image.png() function can be used to access
the image as a PNG binary string. This function is used internally to implement
the IPython integration, which allows images to be viewed directly in IPython
Working with stacks of images¶
Many bioimages contain stacks of 2D images representing a 3D structure. The
jicbioimage.core.image.Image3D class can be used to work with this
type of data.
jicbioimage.core.image.Image3D is a subclass of
numpy.ndarray. To create an instance of a
jicbioimage.core.image.Image3D from a numpy array and assign a
creation event to the history of the 3D image one can use the
To access such a stack from a
jicbioimage.core.image.MicroscopyCollection one can use the
>>> from jicbioimage.core.image import Image3D >>> ar = np.zeros((50, 50, 50), dtype=np.uint8) >>> im3d = Image3D.from_array(ar) >>> im3d.history.creation 'Created Image3D from array'
It is possible to write and read an instance of
jicbioimage.core.image.Image3D as a series of 2D images to and from a
directory using the
jicbioimage.core.image.Image3D.from_directory() class method.