【youcans 的 OpenCV 例程 200 篇】104. 运动模糊退化模型
5.3 模型法估计退化函数
估计图像复原中所用的退化函数,主要有三种方法:观察法、试验法和数学建模方法。
分析导致退化的原因,根据基本原理提出退化模型,如湍流导致的模糊、匀速运动导致的模糊,可以基于模型更加准确地估计退化函数。
下面以运动模糊和大气湍流模型为例,采用退化模型对图像的退化建模。
例程 9.18:运动模糊退化模型
运动模糊是相机,物体,背景间相对运动造成的效果,通常由于长时间曝光或场景内的物体快速移动导致,在摄影中可以借助移动镜头追踪移动的物体来避免。
对匀速线性运动模糊建模,假设图像 
    
     
      
       
        f
       
       
        (
       
       
        x
       
       
        ,
       
       
        y
       
       
        )
       
      
      
       f(x,y)
      
     
    f(x,y) 做平面运动,运动在 x、y 方向的时变分量分别为: 
    
     
      
       
        
         x
        
        
         0
        
       
       
        (
       
       
        t
       
       
        )
       
       
        =
       
       
        a
       
       
        t
       
       
        /
       
       
        T
       
      
      
       x_0(t)=at/T
      
     
    x0(t)=at/T、
    
     
      
       
        
         y
        
        
         0
        
       
       
        (
       
       
        t
       
       
        )
       
       
        =
       
       
        b
       
       
        t
       
       
        /
       
       
        T
       
      
      
       y_0(t)=bt/T
      
     
    y0(t)=bt/T。记录介质上任意点的总曝光量是瞬时曝光量的积分,可以建立运动模糊退化函数模型:
 
     
      
       
        
         H
        
        
         (
        
        
         u
        
        
         ,
        
        
         v
        
        
         )
        
        
         =
        
        
         
          T
         
         
          
           π
          
          
           (
          
          
           u
          
          
           a
          
          
           +
          
          
           v
          
          
           b
          
          
           )
          
         
        
        
         s
        
        
         i
        
        
         n
        
        
         [
        
        
         π
        
        
         (
        
        
         u
        
        
         a
        
        
         +
        
        
         v
        
        
         b
        
        
         )
        
        
         ]
        
        
         
          e
         
         
          
           −
          
          
           j
          
          
           π
          
          
           (
          
          
           u
          
          
           a
          
          
           +
          
          
           v
          
          
           b
          
          
           )
          
         
        
       
       
         H(u,v) = \frac{T}{\pi (ua+vb)} sin[\pi(ua+vb)]e^{-j \pi (ua+vb)} 
       
      
     H(u,v)=π(ua+vb)Tsin[π(ua+vb)]e−jπ(ua+vb)
    # 9.18: 运动模糊退化图像 (Motion blur degradation)
    def motionBlur(image, degree=10, angle=45):
        image = np.array(image)
        center = (degree/2, degree/2)  # 旋转中心
        M = cv2.getRotationMatrix2D(center, angle, 1)  # 无损旋转
        kernel = np.diag(np.ones(degree) / degree)  # 运动模糊内核
        kernel = cv2.warpAffine(kernel, M, (degree, degree))
        blurred = cv2.filter2D(image, -1, kernel)  # 图像卷积
        blurredNorm = np.uint8(cv2.normalize(blurred, None, 0, 255, cv2.NORM_MINMAX))  # 归一化为 [0,255]
        return blurredNorm
    # 运动模糊图像
    img = cv2.imread("../images/Fig0526a.tif", 0)  # flags=0 读取为灰度图像
    imgBlur1 = motionBlur(img, degree=30, angle=45)
    imgBlur2 = motionBlur(img, degree=40, angle=45)
    imgBlur3 = motionBlur(img, degree=60, angle=45)
    plt.figure(figsize=(9, 6))
    plt.subplot(131), plt.title("degree=20"), plt.axis('off'), plt.imshow(imgBlur1, 'gray')
    plt.subplot(132), plt.title("degree=40"), plt.axis('off'), plt.imshow(imgBlur2, 'gray')
    plt.subplot(133), plt.title("degree=60"), plt.axis('off'), plt.imshow(imgBlur3, 'gray')
    plt.tight_layout()
    plt.show()
 

(本节完)
版权声明:
youcans@xupt 原创作品,转载必须标注原文链接:(https://blog.csdn.net/youcans/article/details/123027195)
Copyright 2022 youcans, XUPT
 Crated:2022-2-15










