|
SMIL 1.1.2
|
Smil is a software library intended to handle... images. So, Image is the basic and most important data type under Smil. Near all classes and functions in the library handle an Image data type.
UINT8, UINT16 or UINT32; # create an output image instance before calling erode function
imOut = sp.Image()
r = sp.erode(imIn, imOut, sp.CrossSE())
No matter the past history of imOut, it just need to be already instantiated before function call. The Smil function will adjust everything shall be adjusted.There are several ways to create an instance of an Image :
# create an empty image
im = sp.Image(32, 32)
# draw a rectangle on it
for i in range(8, 24):
for j = range(8, 24):
im.setPixel(i, j, 255)
Note :256, 256, 1UINT8 im = sp.Image('barbara.png')
im = sp.Image('https://example.com/images/barbara.png')
# or
r = sp.getHttpFile('https://example.com/images/lena.png', 'lena.png')
im = sp.Image('lena.png')
im2 = sp.Image(im1)
im2 = sp.Image(im1, 'UINT16')
im2 = sp.Image()
r = sp.clone(im1, im2)
im = sp.Image()
r = sp.read('barbara.png', im)
im = sp.Image
fNames = [ 'slice-{:03d}.png'.format(x) for x in range(0,256) ]
r = sp.read(fNames, im)
type = 'UINT16'
width = 256
height = 384
depth = 512
img = sp.Image(type)
r = sp.readRAW(fname, width, height, depth, img)
png, jpg, tiff, bmp and pbm for 2D images. RAW format can be used to read both 2D and 3D images.NEF, RAF, CR2, ...). See readRAW().png, jpeg, tiff, ...) - tiff is the only file type able to store 3D images and even floating pointing coded images. But Smil doesn't read directly these images.Image(shape=(256,256,1), type=UINT8) : Create an empty image.Image() : Create an empty 2D image with size 256x256Image(szx, szy=1, szz=1], type=UINT8) : Alternative syntax of previous functions (for compatibility)Image(im, clone=False, type=None) : Create an image with the same characteristics than im. Copy the content if clone is True. Change the data type if type is different of None.Image(ndarray) : Create a Smil image from a Numpy array. ndarray type shall be a valid Smil type (UINT8, UINT16 or UINT32)Image(path, raw=False, shape=(256,256,1) , type=UINT8) : create a Smil image from a file. If raw is False, input file type shall be one of valid image file types : .png, .jpg, .tif or .bmp. shape and type are taken into account only for raw file types.Image([path, path, ...], raw=False, shape=(256,256,1), type=UINT8) : create a 3D image from a stack (Python list) of 2D raw images having the same size.Image(url) : create a Smil image from an image file from internet.To save Smil images you have, basically, two functions : write() and writeRAW().
# 2D image
r = sp.write(im2D, 'file.png')
# 3D image
fNames = [ 'image-{:03d}.png'.format(x) for x in range(0, im3D.getDepth()) ]
r = sp.write(im3D, fNames)
r = sp.writeRAW(im, 'image.raw')