import skimage
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from skimage import io
#opencv tensorflow
%matplotlib inline
图像shape
cat = io.imread('./datasets/cat.png')
dog = io.imread('./datasets/dog.png')
df = pd.DataFrame(['Cat', 'Dog'], columns=['Image'])
print(cat.shape, dog.shape)
(168, 300, 3) (168, 300, 3)
cat #0-255,越小的值代表越暗,越大的值越亮
array([[[114, 105, 90],
[113, 104, 89],
[112, 103, 88],
...,
[127, 130, 121],
[130, 133, 124],
[133, 136, 127]],
[[113, 104, 89],
[112, 103, 88],
[111, 102, 87],
...,
[129, 132, 125],
[132, 135, 128],
[135, 138, 131]],
[[111, 102, 87],
[111, 102, 87],
[110, 101, 86],
...,
[132, 134, 133],
[136, 138, 137],
[139, 141, 140]],
...,
[[ 32, 26, 28],
[ 32, 26, 28],
[ 30, 24, 26],
...,
[131, 131, 131],
[131, 131, 131],
[130, 130, 130]],
[[ 33, 27, 29],
[ 32, 26, 28],
[ 31, 25, 27],
...,
[131, 131, 131],
[131, 131, 131],
[130, 130, 130]],
[[ 33, 27, 29],
[ 32, 26, 28],
[ 31, 25, 27],
...,
[131, 131, 131],
[131, 131, 131],
[130, 130, 130]]], dtype=uint8)
#coffee = skimage.transform.resize(coffee, (300, 451), mode='reflect')
fig = plt.figure(figsize = (8,4))
ax1 = fig.add_subplot(1,2, 1)
ax1.imshow(cat)
ax2 = fig.add_subplot(1,2, 2)
ax2.imshow(dog)
<matplotlib.image.AxesImage at 0x1fca229d940>
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-DH30yCyM-1569814787958)(output_4_1.png)]
dog_r = dog.copy() # Red Channel
dog_r[:,:,1] = dog_r[:,:,2] = 0 # set G,B pixels = 0
dog_g = dog.copy() # Green Channel
dog_g[:,:,0] = dog_r[:,:,2] = 0 # set R,B pixels = 0
dog_b = dog.copy() # Blue Channel
dog_b[:,:,0] = dog_b[:,:,1] = 0 # set R,G pixels = 0
plot_image = np.concatenate((dog_r, dog_g, dog_b), axis=1)
plt.figure(figsize = (10,4))
plt.imshow(plot_image)
<matplotlib.image.AxesImage at 0x1fca2408828>
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pueVWdNl-1569814787959)(output_5_1.png)]
dog_r
array([[[160, 0, 0],
[160, 0, 0],
[160, 0, 0],
...,
[113, 0, 0],
[113, 0, 0],
[112, 0, 0]],
[[160, 0, 0],
[160, 0, 0],
[160, 0, 0],
...,
[113, 0, 0],
[113, 0, 0],
[112, 0, 0]],
[[160, 0, 0],
[160, 0, 0],
[160, 0, 0],
...,
[113, 0, 0],
[113, 0, 0],
[112, 0, 0]],
...,
[[165, 0, 0],
[165, 0, 0],
[165, 0, 0],
...,
[212, 0, 0],
[211, 0, 0],
[210, 0, 0]],
[[165, 0, 0],
[165, 0, 0],
[165, 0, 0],
...,
[210, 0, 0],
[210, 0, 0],
[209, 0, 0]],
[[164, 0, 0],
[164, 0, 0],
[164, 0, 0],
...,
[209, 0, 0],
[209, 0, 0],
[209, 0, 0]]], dtype=uint8)
灰度图
fig = plt.figure(figsize = (8,4))
ax1 = fig.add_subplot(2,2, 1)
ax1.imshow(cgs, cmap="gray")
ax2 = fig.add_subplot(2,2, 2)
ax2.imshow(dgs, cmap='gray')
<matplotlib.image.AxesImage at 0x1fca2353358>
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ubAz9Xzt-1569814787959)(output_8_1.png)]