In [1]:
from PIL import Image
import numpy as np
In [2]:
im = np.array(Image.open('data/src/lena.jpg'))
In [3]:
print(type(im))
In [4]:
print(im.dtype)
In [5]:
print(im.shape)
In [6]:
im_gray = np.array(Image.open('data/src/lena.jpg').convert('L'))
In [7]:
print(im_gray.shape)
In [8]:
print(im.flags.writeable)
In [9]:
print(im[0, 0, 0])
In [10]:
im[0, 0, 0] = 0
In [11]:
print(im[0, 0, 0])
In [12]:
im_as = np.asarray(Image.open('data/src/lena.jpg'))
In [13]:
print(type(im_as))
In [14]:
print(im_as.flags.writeable)
In [15]:
# im_as[0, 0, 0] = 0
# ValueError: assignment destination is read-only
In [16]:
im_f = im.astype(np.float64)
print(im_f.dtype)
In [17]:
im_f = np.array(Image.open('data/src/lena.jpg'), np.float64)
print(im_f.dtype)
In [18]:
print(im_gray.dtype)
In [19]:
pil_img = Image.fromarray(im)
print(pil_img.mode)
In [20]:
pil_img.save('data/temp/lena_save_pillow.jpg')
In [21]:
pil_img_gray = Image.fromarray(im_gray)
print(pil_img_gray.mode)
In [22]:
pil_img_gray.save('data/temp/lena_save_pillow_gray.jpg')
In [23]:
Image.fromarray(im).save('data/temp/lena_save_pillow.jpg')
Image.fromarray(im_gray).save('data/temp/lena_save_pillow_gray.jpg')
In [24]:
# pil_img = Image.fromarray(im_f)
# TypeError: Cannot handle this data type
In [25]:
pil_img = Image.fromarray(im_f.astype(np.uint8))
pil_img.save('data/temp/lena_save_pillow.jpg')