Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()

like image 283
xdze2 Avatar asked Dec 01 '17 18:12

xdze2


People also ask

Can an image could be converted into a Numpy array?

Images are an easier way to represent the working model. In Machine Learning, Python uses the image data in the format of Height, Width, Channel format. i.e. Images are converted into Numpy Array in Height, Width, Channel format.


1 Answers

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)
like image 181
Pranasas Avatar answered Sep 21 '22 19:09

Pranasas