Open iansilva6 opened 5 years ago
import matplotlib.pyplot as plt
from skimage import data from skimage.color import rgb2hsv img2 = plt.imread('hbol.jpg')
r = img2[:, :, 0] g = img2[:, :, 1] b = img2[:, :, 2]
plt.imshow(r, cmap='gray') plt.show() plt.imshow(g, cmap='gray') plt.show() plt.imshow(b, cmap='gray') plt.show()
from skimage import data from skimage.color import rgb2hsv from skimage.color import convert_colorspace
img2 = plt.imread('hbol.jpg') img_hsv = convert_colorspace(img2, 'RGB', 'HSV') h = img_hsv[:, :, 0] s = img_hsv[:, :, 1] v = img_hsv[:, :, 2] plt.imshow(s) plt.show()
from PIL import Image from numpy import *
imgp = Image.open('hbol.jpg')
dim = (100, 180, 200, 270) crop_img = imgp.crop(dim) im = array(crop_img) plt.imshow(im) plt.show()
im = Image.open('homer.jpg') im = array(im) print(im.min()) print(im.max()) print(im.mean())
print(np.median(im))
print(np.std(im))
print(np.var(im)) r = im[:, :, 0] g = im[:, :, 1] b = im[:, :, 2] plt.subplots_adjust(hspace=0.5, wspace=0.5) plt.subplot(2, 2, 1) plt.title("Imagem Original") plt.imshow(im) hist, bins = np.histogram(r.ravel(), bins= 256, range=(0, 256)) plt.subplot(2, 2, 2) plt.title("Histograma Vermelhor") plt.bar(bins[:-1], hist) hist, bins = np.histogram(g.ravel(), bins= 256, range=(0, 256)) plt.subplot(2, 2, 3) plt.title("Histograma Verde") plt.bar(bins[:-1], hist) hist, bins = np.histogram(b.ravel(), bins= 256, range=(0, 256)) plt.subplot(2, 2, 4) plt.title("Histograma Azul") plt.bar(bins[:-1], hist) plt.show()
def normalize(f): lmin = float(f.min()) lmax = float(f.max()) return np.floor((f-lmin)/(lmax-lmin) * 255.)
im2 = normalize(r) plt.subplots_adjust(hspace=0.5, wspace=0.5) plt.subplot(2, 2, 1) plt.imshow(im2) plt.subplot(2, 2, 2) plt.imshow(r) plt.show
from skimage import exposure im_eq = exposure.equalize_hist(b) im_adapthist = exposure.equalize_adapthist(b, clip_limit=0.05) saida = [b, im_eq, im_adapthist] title = ['Blue', 'Histograma equalizado', ' Equalização adaptativa'] for i in range(3): plt.subplot(3, 1, i+1) plt.imshow(saida[i], cmap = 'gray') plt.title(title[i]) plt.axis('off') plt.show()
from skimage.color import rgb2gray, rgb2gray img_gray = rgb2gray(im) plt.subplots_adjust(hspace=0.5, wspace=0.5) plt.subplot(2, 2, 1) plt.title("Imagem Original") plt.imshow(im) hist, bins = np.histogram(im.ravel(), bins= 256, range=(0, 256)) plt.subplot(2, 2, 2) plt.title("Histograma") plt.bar(bins[:-1], hist) plt.show
plt.subplots_adjust(hspace=0.5, wspace=0.5) plt.subplot(2, 2, 1) plt.imshow(img_gray, cmap='gray') plt.title('Original') plt.subplot(2, 2, 2) plt.hist(img_gray.ravel(), 256, range=(0,1)) plt.title('Histograma') plt.show
Redimensionamento e rotação
import numpy as np import matplotlib.pyplot as plt from skimage.transform import resize, rotate
Leitura da imagem
img = plt.imread('./image01.jpg') l,a,c = img.shape
Redimencionamento
img_red = resize(img, (l / 2, a / 2))
Rotacionar imagem
img_rot = rotate(img, 90, resize=True)
plt.imshow(img) plt.show() plt.imshow(img_red) plt.show() plt.imshow(img_rot) plt.show() plt.imsave('img_red.jpg', img_red)