Input/Output#
Reading images#
The imread() reads a grayscale or color image from the file specified by a filename.
Return value is a SpatialImage. All images are returned as 3D images. Images
that are only 2D are upgraded to 3D images (with only one slice). 3D images are returned as SX*SY*SZ images. RGB or RGBA images add
a fourth dimension (of size 3 or 4) to the returned array.
Supported formats are Inrimage (.inr), TIFF (.tif), LSM (.lsm) and more common formats like PNG, JPG, BMP…
The reader tries to retreive voxel sizes data from image files and it is stored in the “resolution” attribute of the returned SpatialImage.
1from openalea.image.serial.all import imread
2im = imread("lena.bmp")
Saving images#
imsave() writes exclusively SpatialImage instances.
The writer is selected by looking at the extension. The directory where the file is written must exist.
1from openalea.image.serial.all import imread, imsave
2im = imread("lena.bmp")
3# -- process im as much as you want --
4imsave("lena_2.png", im)