Search code examples
pythonnumpypdfwandndimage

How to convert a wand image object to numpy array (without OpenCV)?


I am converting pdf files to image using Wand. Then, I do further image processing using ndimage.

I would like to directly convert the Wand image into a ndarray... I have seen the answer here, but it use OpenCV. Is this possible without using OpenCV?

For the moment I save a temporary file, which is re-opened with scipy.misc.imread()


Solution

  • As of Wand 0.5.3 this is supported directly

    import numpy as np
    from wand.image import Image
    
    with Image(filename='rose:') as img:
        array = np.array(img)
        print(array.shape)  #=> (70, 46, 3)