import matplotlib.pyplot as pltimport numpy as np### 两个图片的列合并In [12]:
o=plt.imread('onr.jpg')plt.imshow(o)o.shapeOut[12]:
(456, 334, 3)
In [28]:
m=plt.imread('mj.jpg')plt.imshow(m)m.shapeOut[28]:
(480, 640, 3)
In [37]:
plt.imshow(m[100:130,300:350][::2,::2])mm = m.copy()plt.imshow(mm)Out[37]:
<matplotlib.image.AxesImage at 0x1c84f866a58>
plt.imshow(np.concatenate([o[:,:],m[0:456,:]],axis=1)) ### 注意:### 图片二比图片一大,axis=1列对齐,行宽相等,取较小的图片的行数比例### axis : 0 行合并(y) , 1 列合并(x) , -1 本维度的最后一个维度### 马赛克z = m[100:130,300:350][::5,::5]plt.imshow(z)In [78]:
z.shapeOut[78]:
(6, 10, 3)In [62]:
plt.imshow(m[100:130,300:350])Out[62]:
<matplotlib.image.AxesImage at 0x1c84f1bbb38>
### 图片据部马赛克mm = m.copy()for i in range(6): for j in range(10): mm[100+5*i:105+5*i,300+5*j:305+5*j]=m[100+5*i:105+5*i,300+5*j:305+5*j][::5,::5]In [80]:
plt.imshow(mm)Out[80]:
<matplotlib.image.AxesImage at 0x1c850f56668>
In [70]:
plt.imshow(m[0:200,200:400][::10,::10])Out[70]:
<matplotlib.image.AxesImage at 0x1c84fc5c978>
In [75]:
z = m.copy()for i in range(20): for j in range(20): z[0+10*i:10+10*i,200+10*j:210+10*j]=m[0+10*i:10+10*i,200+10*j:210+10*j][::10,::10]In [76]:
plt.imshow(z)Out[76]:
<matplotlib.image.AxesImage at 0x1c84fd6f978>
### 图片的替换plt.imshow(o)In [82]:
plt.imshow(o[200:280,110:230])Out[82]:
<matplotlib.image.AxesImage at 0x1c851002cf8>
In [160]:
o[200:290,120:220].shapeOut[160]:
(90, 100, 3)In [161]:
v = m.copy()mm = v[100:130,300:350]plt.imshow(mm)Out[161]:
<matplotlib.image.AxesImage at 0x1c8536415c0>
In [162]:
o[200:290,120:220][::3,::2].shapeOut[162]:
(30, 50, 3)In [163]:
oo = o[200:290,120:220][::3,::2]oo.shapeOut[163]:
(30, 50, 3)In [168]:
v[100:130,300:350]=o[200:290,120:220][::3,::2]# mm = ooIn [169]:
plt.imshow(v)Out[169]:
<matplotlib.image.AxesImage at 0x1c853745eb8>
ndarray.reshape(tuple)
tuple是新形状的参数
元素的总量不能变化
In [134]:
lj.shapeOut[134]:
(483, 483, 3)In [139]:
lj.sizeOut[139]:
699867In [140]:
483*483*3Out[140]:
699867In [143]:
lj.reshape((483*483*3,1))Out[143]:
array([[35],
[36],
[31],
...,
[42],
[43],
[35]], dtype=uint8)#矩阵的偏平化In [153]:
lj.reshape(-1)Out[153]:
array([35, 36, 31, ..., 42, 43, 35], dtype=uint8)In [152]:
A = np.array([1,2,3,4,5,6,7,8,9,10])A.reshape(-1,1)Out[152]:
array([[ 1],
[ 2],
[ 3],
[ 4],
[ 5],
[ 6],
[ 7],
[ 8],
[ 9],
[10]])ndarray.ravel() 偏平化In [154]:
lj.ravel()Out[154]:
array([35, 36, 31, ..., 42, 43, 35], dtype=uint8)