Practical Python and OpenCV iv
Chapter VI Image Processing
这一章的内容是最多的!!!
这章首先是基本的图像处理:translation,rotation,resizing,flipping,and cropping
然后是image arithmetic,bitwise operations,and masking
translation:
![](https://img.haomeiwen.com/i2907791/cc494c3f18f5af2a.png)
[1,0,25]的意思是往(1,0)的方向移动25个pixels,同理[0,1,50]的意思是往(0,1)的方向移动50个pixels
我猜想(1,1,50)的意思往(1,1)的方向移动50个pixels,这个猜想不对,见图:
![](https://img.haomeiwen.com/i2907791/284466bd5cff02a7.png)
接下来是Rotation:
![](https://img.haomeiwen.com/i2907791/be1fd37cde1bf302.png)
(w,h)就是旋转的原点,getRotationMatrix2D的最后一个参数是the scale of the image,放缩比例
Resizing:
![](https://img.haomeiwen.com/i2907791/bdbd6aa86ee574e9.png)
Flipping:
![](https://img.haomeiwen.com/i2907791/0ced1bd8c581998e.png)
![](https://img.haomeiwen.com/i2907791/ee45f731263f991c.png)
![](https://img.haomeiwen.com/i2907791/c4dc1f285acb5318.png)
Cropping:
在前面的chapter用过cropping了,是通过numpy的slicing
Image Arithmetic
opencv的加法 和 numpy的加法是不一样的,越界了numpy是取模而opencv是取界限值
![](https://img.haomeiwen.com/i2907791/8b9d51ab8145c2c8.png)
对图像所有像素加100和所有像素减50的效果:
![](https://img.haomeiwen.com/i2907791/cadd862a09a790e1.png)
BITWISE OPERATION:
4种基本的位操作:AND,OR,XOR,and NOT
如果有两个大小相等的图A和B 都是有黑或者白组成,
那么图A and 图b 两个都是白的区域 and出来还是白的,
图A or 图B 只要有一个图某个区域是白的 or出来就是白的
图A xor 图B 两个图某个区域都是白或者都是黑 xor出来的就是黑的其余的位置就是白的
Masking:
Using a mask allows us to focus only on the portions of the image that interests us
用黑白图与图像进行and操作就能得到cropping的效果
SPLITTING AND MERGING CHANNELS:
用split将图像分成三个通道的图像:分出来的是灰度图
![](https://img.haomeiwen.com/i2907791/04f857c3478f8d35.png)
灰度度变成彩色图:
![](https://img.haomeiwen.com/i2907791/958a72f4204cb1ab.png)
COLOR SPACES:
除了RGB color space 还有很多其他的spaces
比如HSV Hue-Saturation-Value 或者 L*a*b*
![](https://img.haomeiwen.com/i2907791/d92bc3f13ce4c901.png)
康康扩展包https://ppao.pyimagesearch.com/lessons/ppao-chapter-6-image-processing/
扩展包里面有几个例子 关于不同color spaces的作用