SMIL 1.1.1
Loading...
Searching...
No Matches
numpy_sp2np2sp.py
1
2import smilPython as sm
3import numpy as np
4
5# read a 16 bits RAW Image
6file = "Slices-16.raw"
7im16 = sm.Image('UINT16')
8sp.readRAW(file, 700, 700, 700, im16)
9
10# Let's convert 8 bit input image
11
12# get a pointer to a numpy array
13p16 = im16.getNumpyArray()
14
15# scale pixel values from 2**16 to 2**8
16p16 //= 256
17
18# get a new 8 bit numpy array
19p8 = p.astype('uint8')
20
21# create a 8 bits image with the same dimensions of the 16 bit image
22im8 = sm.Image(im16, 'UINT8')
23# come back to Smil Image
24im8.fromNumpyArray(p8)
25