运动模糊分析
1、运动模糊产生原因:
代码:
1、
import math import numpy as np import cv2 #生成卷积核和锚点 def genaratePsf(length,angle): EPS=np.finfo(float).eps alpha = (angle-math.floor(angle/ 180) *180) /180* math.pi cosalpha = math.cos(alpha) sinalpha = math.sin(alpha) if cosalpha < 0: xsign = -1 elif angle == 90: xsign = 0 else: xsign = 1 psfwdt = 1; #模糊核大小 sx = int(math.fabs(length*cosalpha + psfwdt*xsign - length*EPS)) sy = int(math.fabs(length*sinalpha + psfwdt - length*EPS)) psf1=np.zeros((sy,sx)) #psf1是左上角的权值较大,越往右下角权值越小的核。 #这时运动像是从右下角到左上角移动 for i in range(0,sy): for j in range(0,sx): psf1[i][j] = i*math.fabs(cosalpha) - j*sinalpha rad = math.sqrt(i*i + j*j) if rad >= half and math.fabs(psf1[i][j]) <= psfwdt: temp = half - math.fabs((j + psf1[i][j] * sinalpha) / cosalpha) psf1[i][j] = math.sqrt(psf1[i][j] * psf1[i][j] + temp*temp) psf1[i][j] = psfwdt + EPS - math.fabs(psf1[i][j]); if psf1[i][j] < 0: psf1[i][j] = 0 #运动方向是往左上运动,锚点在(0,0) anchor=(0,0) #运动方向是往右上角移动,锚点一个在右上角 #同时,左右翻转核函数,使得越靠近锚点,权值越大 if angle<90 and angle>0: psf1=np.fliplr(psf1) anchor=(psf1.shape[1]-1,0) elif angle>-90 and angle<0:#同理:往右下角移动 psf1=np.flipud(psf1) psf1=np.fliplr(psf1) anchor=(psf1.shape[1]-1,psf1.shape[0]-1) elif anchor<-90:#同理:往左下角移动 psf1=np.flipud(psf1) anchor=(0,psf1.shape[0]-1) psf1=psf1/psf1.sum() return psf1,anchor
2、
import numpy as np def motion_blur(image, degree=10, angle=20): image = np.array(image) # 这里生成任意角度的运动模糊kernel的矩阵, degree越大,模糊程度越高 M = cv2.getRotationMatrix2D((degree/2, degree/2), angle, 1) motion_blur_kernel = np.diag(np.ones(degree)) motion_blur_kernel = cv2.warpAffine(motion_blur_kernel, M, (degree, degree)) motion_blur_kernel = motion_blur_kernel / degree blurred = cv2.filter2D(image, -1, motion_blur_kernel) # convert to uint8 cv2.normalize(blurred, blurred, 0, 255, cv2.NORM_MINMAX) blurred = np.array(blurred, dtype=np.uint8) return blurred
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
2017-12-15 Hard Negative Mning