Actually I'd like to insert JPEG images without decoding (to save place) into a data frame (pandas) when I got stuck at the phase of loading the images properly to able to read back them with PIL.
from PIL import Image
with open(fname, "rb") as f:
data = f.read()
img = Image.frombytes('RGB',d,data)
img = np.asarray(map(ord,img))
I found a solution above with ord() but is a bit slow. Is there any faster method?
I've resolved the problem, thank you!
Best How To :
You can use
mahotas which is a popular library to reading/quantifying image. Install it via terminal
pip install mahotas.
import mahotas as mh
import numpy as np
original_img = np.array(mh.imread('figure1.jpg'), dtype=np.float64) / 255
# check dimension, RGB
Out: (1536, 2048, 3)
width, height, depth = original_img.shape
image_flattened = np.reshape(original_img, (width*height, depth))
Out: (3145728, 3)