Python OpenCV 简单图像比较
2015-01-15 16:41
731 查看
项目需要做两张图像比较的差,感觉Python用起来很方便,手头正好有OpenCV。红绿代表插值正负,为了更好的可视化,差值均放大10倍显示。
image1
image2
dif
import cv2 def clmap(v, k, upBound): #mul and clamp val = v * k if val > upBound: return upBound else: return val inImage_1 = 'B_Tri.bmp' # inImage_2 = 'B_RT.bmp' # dif_img = 'dif_' + inImage_1 img_1 = cv2.imread(inImage_1) # read as color image img_2 = cv2.imread(inImage_2) dif = img_1.copy() show_dif = dif.copy() # dif image for show only width = img_1.shape[0] #get width height = img_1.shape[1] #get height for i in range(width): for j in range(height): #dif[i, j] = [128,0,0] # b g r #print img_1[i,j]-img_2[i,j] diff = int(img_1[i,j][0])-int(img_2[i,j][0]) if diff < 0: show_dif[i,j] = [0,clmap(abs(diff), 10, 255), 0] elif diff > 0: show_dif[i, j]= [0, 0, clmap(abs(diff), 10, 255)] else: show_dif[i,j] = [0] dif[i,j] = [abs(diff)] * 3 print dif_img print 'different data:' print 'max : ', dif.max() print 'min : ', dif.min() print 'mean : ', dif.mean() cv2.imwrite(dif_img, show_dif) cv2.imshow('_dif',show_dif) cv2.waitKey(0) cv2.destroyAllWindows()
image1
image2
dif
相关文章推荐
- python-opencv(cv2) 之一 图像的简单读取
- 图像识别 python+opencv的简单人脸识别
- Python下opencv使用笔记(一)(图像简单读取、显示与储存)
- opencv for python 之 简单的图像变化
- Python OpenCV学习笔记之:图像直方图反向投影(backprojection)原理简单实现
- python深度学习库pytorch::transforms练习:opencv,scikit-image,PIL图像处理库比较
- python-opencv笔记 图像的读取和简单几何图形绘制
- Python下opencv使用笔记(一)(图像简单读取、显示与储存)
- 用OpenCV-Python 完成简单的图像读取,显示
- Python下opencv使用笔记(二)(简单几何图像绘制)
- 图像识别 python+opencv的简单人脸识别
- Python3与OpenCV3.3 图像处理(一)--环境搭建与简单DEMO
- python 简单图像处理(2) 镜像
- python 简单图像处理(14) 灰度图腐蚀和膨胀,开运算、闭运算
- python 简单图像处理(11) 空间域图像锐化(边缘检测)
- 图像处理中各种边缘检测的微分算子简单比较(Sobel,Robert, Prewitt,Laplacian,Canny)
- python 简单图像处理(15) 图像的傅立叶变换
- python 简单图像处理(7) 计算直方图
- python 简单图像处理(3) 平移
- python的由来与简单比较