In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
O matplotlib possui a leitura nativa de imagens no formato png. Quando este formato é lido, a imagem é automaticamente mapeada da faixa 0 a 255 contido no pixel uint8 da imagem para float 0 a 1 no pixel do array lido
Já se o formato for outro, se o PIL estiver instalado, a leitura é feita pelo PIL e neste caso o tipo do pixel é mantido em uint8, de 0 a 255. Veja no exemplo a seguir
In [2]:
f = mpimg.imread('../data/cameraman.tif')
print(f.dtype,f.shape,f.max(),f.min())
In [3]:
fcor = mpimg.imread('../data/boat.tif')
print(fcor.dtype,fcor.shape,fcor.max(),fcor.min())
In [4]:
fcor2 = mpimg.imread('../figures/capa_IA898.png')
print(fcor2.dtype, fcor2.shape, fcor2.max(), fcor2.min())
In [6]:
%matplotlib inline
plt.imshow(f, cmap='gray')
plt.colorbar()
Out[6]:
In [7]:
plt.imshow(fcor)
plt.colorbar()
Out[7]:
In [8]:
plt.imshow(fcor2)
plt.colorbar()
Out[8]:
In [10]:
plt.imshow(fcor2)
plt.imshow(fcor)
plt.imshow(f, cmap='gray')
Out[10]:
In [2]:
import numpy as np
import sys,os
ia898path = os.path.abspath('../../')
if ia898path not in sys.path:
sys.path.append(ia898path)
import ia898.src as ia
In [3]:
f = ia.nbread('../figures/capa_IA898.png')
print(f.shape)
In [8]:
plt.imshow(f)
Out[8]:
In [4]:
f = ia.nbread('../../ia636/ia636/images/wheel.png')
print(f.shape)
plt.imshow(f,cmap='gray')
Out[4]:
In [3]:
f = ia.nbread('../../ia636/ia636/images/blobs.pbm')
print(f.shape,f.dtype)
plt.imshow(f,cmap='gray')
In [14]:
import PIL
from PIL import Image
image_path = '../../ia636/ia636/images/blobs.pbm'
with Image.open(image_path) as image:
im_arr = np.fromstring(image.tobytes(), dtype=np.uint8)
print(im_arr.shape)
print(image.size)
print(image.mode)
#print(image.)
In [ ]: