Exemplo n.º 1
0
 def build_gauss_pyr(self, base):  #---- 建立高斯金字塔
     intvls = self.intvls
     # 影像金字塔每一層有幾個分頁 =3
     sigma = self.sigma
     # 影像最開始的 高斯平滑參數=1.6
     octvs = self.octvs
     # 高斯金字塔有幾層
     k = 2**(1 / intvls)
     # =2^(0.333)
     sig = np.zeros(intvls + 3)
     # 每一頁的 sigma
     sig[0] = sigma
     sig[1] = sigma * np.sqrt(k * k - 1)
     for i in range(2, intvls + 3):
         sig[i] = sig[i - 1] * k
     gauss_pyr = []
     # 輸出高斯金字塔
     for o in range(0, octvs):
         if o == 0:
             pyramid = np.zeros((base.shape[0], base.shape[1], intvls + 3))
             pyramid[:, :, 0] = base
         else:
             pyramid = self.downsample_by2(gauss_pyr[o - 1][:, :, intvls])
         for i in range(1, intvls + 3):
             pyramid[:, :, i] = CVP.Gauss_blur2D(pyramid[:, :, i - 1],
                                                 sigma=sig[i])
         gauss_pyr.append(pyramid)
     return gauss_pyr
Exemplo n.º 2
0
 def pre_processing(self, src_img):
     # 執行以下動作: (1)轉灰階圖 (2)將資料改成[0~1] (3)影像放大2倍 (4)Gauss smooth
     gray = CVP.rgb2gray(src_img)
     # 灰階圖
     if np.max(gray) > 2:
         gray = gray / 256
         # 影像強度正規化到 [0 ~ 1]
     #doubled = CVP.resize(gray,ratio=2);         # 雙倍影像圖
     if self.doubled == True:
         doubled = CVP.resize(gray, ratio=2)
         # 雙倍影像圖
     else:
         doubled = gray
     sig_diff = np.sqrt(self.sigma**2 - 4 * self.init_sigma**2)
     # s=1.25
     init_img = CVP.Gauss_blur2D(doubled, sigma=sig_diff)
     return init_img