图像增强
为了做项目我测试不同的插值算法来实现自己的数据控制
参考脚本博客:https://blog.****.net/JNingWei/article/details/78822026
我适当修改代码
相关操作如下:
# coding=utf-8
import cv2
"""
INTER_NEAREST | 最近邻插值
INTER_LINEAR | 双线性插值(默认设置)
INTER_AREA | 使用像素区域关系进行重采样
INTER_CUBIC | 4x4像素邻域的双三次插值
INTER_LANCZOS4 | 8x8像素邻域的Lanczos插值
"""
if __name__ == '__main__':
#dirfile =( 'C:/Users/Administrator/Pictures/l.jpg')
# img = cv2.imread(dirfile)
img = cv2.imread('C:/Users/Administrator/Desktop/tin.jpg')
height, width = img.shape[:2]
# 缩小图像
size = (int(width*0.8), int(height*0.7))
shrink_NEAREST = cv2.resize(img, size, interpolation=cv2.INTER_NEAREST)
shrink_LINEAR = cv2.resize(img, size, interpolation=cv2.INTER_LINEAR)
shrink_AREA = cv2.resize(img, size, interpolation=cv2.INTER_AREA)
shrink_CUBIC = cv2.resize(img, size, interpolation=cv2.INTER_CUBIC)
shrink_LANCZOS4 = cv2.resize(img, size, interpolation=cv2.INTER_LANCZOS4)
# 放大图像
fx = 1.2
fy = 1.1
enlarge_NEAREST = cv2.resize(img, (0, 0), fx=fx, fy=fy, interpolation=cv2.INTER_NEAREST)
enlarge_LINEAR = cv2.resize(img, (0, 0), fx=fx, fy=fy, interpolation=cv2.INTER_LINEAR)
enlarge_AREA = cv2.resize(img, (0, 0), fx=fx, fy=fy, interpolation=cv2.INTER_AREA)
enlarge_CUBIC = cv2.resize(img, (0, 0), fx=fx, fy=fy, interpolation=cv2.INTER_CUBIC)
enlarge_LANCZOS4 = cv2.resize(img, (0, 0), fx=fx, fy=fy, interpolation=cv2.INTER_LANCZOS4)
# 保存图像
cv2.imwrite("shrink_NEAREST.jpg", shrink_NEAREST)
cv2.imwrite("shrink_LINEAR.jpg", shrink_LINEAR)
cv2.imwrite("shrink_AREA.jpg", shrink_AREA)
cv2.imwrite("shrink_CUBIC.jpg", shrink_CUBIC)
cv2.imwrite("shrink_LANCZOS4.jpg", shrink_LANCZOS4)
cv2.imwrite("enlarge_NEAREST.jpg", enlarge_NEAREST)
cv2.imwrite("enlarge_LINEAR.jpg", enlarge_LINEAR)
cv2.imwrite("enlarge_AREA.jpg", enlarge_AREA)
cv2.imwrite("enlarge_CUBIC.jpg", enlarge_CUBIC)
cv2.imwrite("enlarge_LANCZOS4.jpg", enlarge_LANCZOS4)
cv2.waitKey(0)
原图
处理后:
![在这里插入图片描述](https://img-blog.****img.cn/20190104164857826.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3l1bnhpbmFu,size_16,color_FFFFFF,t_70