I was very happy to find the PythonMagick bindings, which actually allow me to reliably load 16-bit images. Yay! Thanks guys!
The bindings are, however, incomplete, which I'm sure you know, given that the last patch was about adding the MagickCore::ColorspaceType enum. There are other enums missing, making several exposed functions useless. One example: missing MagickCore::ImageType enum makes using Image::type() to make a grayscale image quite hard (quantizeColorSpace() doesn't work). What is also missing is the Image.data attribute documented here. Combined with str/bytes inconsistencies in the Blob class, they make accessing raw pixel data quite hard. I spent two days trying to find a reliable way to move data into a numpy array, and the best I could get was
Code: Select all
image = PythonMagick.Image(filename)
blob = PythonMagick.Blob()
image.write(blob, 'RGB', 16)
rawdata = b64decode(blob.base64())
img = np.ndarray((image.rows(), image.columns(), 3),
dtype='uint16', buffer=rawdata)
Code: Select all
cmap = 'RGB'
blob = PythonMagick.Blob()
blob.base64(b64encode(bytes(array)).decode('ascii'))
image = PythonMagick.Image(blob, PythonMagick.Geometry(width, height), 16, cmap)