示例#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
示例#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
示例#3
0
 def plot_pyramid(pyr, start=0, end=0, **kwargs):
     """
     @ src  : 影像金字塔
     @ start: 從第幾層開始
     @ end  : 到弟幾層
     @ figx,figy: 影像大小
     """
     layers = np.size(pyr)
     # 金字塔有幾層
     if end == 0:
         end = layers
         # 最後第幾層
     if pyr[0].ndim == 2:
         pages = 1
         # 每一層有幾個分頁
     if pyr[0].ndim == 3: pages = pyr[0].shape[2]
     ymax = 0
     xmax = 0
     ys = np.zeros(end - start)
     # 每一層的起始位置Y
     #---- ----
     for octv in range(start, end):  #-- 計算位置
         ys[octv - start] = ymax
         ymax += pyr[octv].shape[0]
         xmax = np.maximum(xmax, pyr[octv].shape[1] * pages)
     dest = np.zeros((ymax, xmax))
     #---- ----
     for octv in range(start, end):  #-- 填入資料
         base = pyr[octv]
         rows = base.shape[0]
         cols = base.shape[1]
         for page in range(0, pages):
             if pages > 1: img = base[:, :, page]
             if pages == 1: img = base[:, :]
             y1 = ymax - (ys[octv - start]).astype(int) - rows
             x0 = page * cols
             dest[y1:y1 + rows, x0:x0 + cols] = img
     if kwargs.get('normalize'):  #-- 調整動態範微
         dmax = np.max(dest)
         dmin = np.min(dest)
         dest = (dest - dmin) / (dmax - dmin)
         dmax = np.max(dest)
         dmin = np.min(dest)
     CVP.imshow(dest, **kwargs)
     plt.show()
示例#4
0
 def focal_correct(PAN):                         #---- project image to cylindrical
   """ imgs[k]:     kth source image without correction
       imgc[k]:     kth image with focal length correction
   """
   hfov= PAN.hfov;
   for k in range(0, PAN.count):
     src = PAN.imgs[k];
     imgc= CVP.projection_3D(src, hfov= hfov, fl=None, mode='plane_to_cylindrical'); 
     PAN.imgc.append(imgc);
示例#5
0
 def brightness_compensation(PAN):               #---- brightness compensation
   #--- reference (no boundary but blurred) ---
   ref = pano_tools.paste_and_blend(PAN, src= PAN.imgb, bw=70);
   gref= CVP.rgb2gray(ref);
   H   = PAN.H.copy();  
   xa  = np.argmin(H[:,6]); x0  = int(np.ceil(PAN.imgb[xa].shape[1]/2));
   ya  = np.argmin(H[:,5]); y0  = int(np.ceil(PAN.imgb[ya].shape[0]/2));
   box_ratio = 0.99;
   #--- ---
   for k in range(0,PAN.count):          
     #--- capture source sampling window ---  
     imgb= CVP.rgb2gray(PAN.imgb[k]); 
     rowh= int(imgb.shape[0]/2);                 # half image height
     colh= int(imgb.shape[1]/2);                 # half image width        
     roww= int(rowh* box_ratio);                 # capture window radius
     colw= int(colh* box_ratio);
     imgs= imgb[rowh-roww:rowh+roww, colh-colw:colh+colw]
     cdfs= pano_tools.brightness_cdf(imgs);      # brightness curve for source         
     #--- capture reference sampling window ---  
     yr  = int(y0+ H[k,5]);
     xr  = int(x0+ H[k,6]);
     imgr= gref[yr-roww:yr+roww, xr-colw:xr+colw];
     cdfr= pano_tools.brightness_cdf(imgr);      # brightness curve for reference         
     #---  brightness equalization ---
     out = np.zeros_like(PAN.imgb[k]);           # image with brightness compensation
     for kb in range(0,256):
       under= np.sum(cdfr< cdfs[kb]);            # 
       under= np.minimum(under, 3*(kb+0.5)-0.5); # prevent from low gain boost
       gain = (under+0.5)/(kb+0.5); 
       #--- find pixel---
       th0  = kb/256; th1 = (kb+1)/256;          # bin lower and upper bound
       mask = ((imgb<th1)+0) - ((imgb<=th0)+0)   # data inside the region
       mask = mask* gain;
       out[:,:,0]+= PAN.imgt[k][:,:,0]*mask;
       out[:,:,1]+= PAN.imgt[k][:,:,1]*mask; 
       out[:,:,2]+= PAN.imgt[k][:,:,2]*mask; 
     PAN.imgb[k] = out;          
示例#6
0
    PAN.upload(plt.imread('taipei_03.jpg') / 256)
    PAN.upload(plt.imread('taipei_04.jpg') / 256)
    PAN.upload(plt.imread('taipei_05.jpg') / 256)
    pano_tools.plot_source_images(PAN)
    # plot source images
#=================================================== Auto execution
if 1 == 0:
    pano_tools.focal_correct(PAN)
    pano_tools.extract_features(PAN)
    # extract features
    pano_tools.pairing(PAN, th=None)
    # pairing feature points
    pano_tools.floorplan(PAN, tilt1=3.5)
    pano_tools.transform(PAN)
    pano_tools.registry(PAN, bw=25, box_th=None)
    CVP.imshow(PAN.result, figy=8, ticks='off')

#=================================================== Step 1: focal length correct
if 1 == 0:
    pano_tools.focal_correct(PAN)
    pano_tools.plot_focal_correct(PAN)
    # plot source images
#=================================================== Step 2: extract features
if 1 == 0:
    pano_tools.extract_features(PAN)
    # extract features
    pano_tools.plot_features(PAN)
    # plot keypoints for image 0
#=================================================== Step 3: Pairing
if 1 == 0:
    pano_tools.pairing(PAN, th=None)
示例#7
0
 def plot_transform(PAN):                        #---- plot registry images
   for k in range(0, np.shape(PAN.imgt)[0]):
     CVP.imshow(PAN.imgt[k],figy=6,ticks='off');
     print('image no:',k);
示例#8
0
 def plot_focal_correct(PAN):                    #---- plot source image base      
   for k in range(0, np.shape(PAN.imgc)[0]): 
     CVP.imshow(PAN.imgc[k],figy=6,ticks='off');
     print('image no:',k);
示例#9
0
 def plot_source_images(PAN) :                   #---- plot source image base
   for k in range(0, np.shape(PAN.imgs)[0]): 
     CVP.imshow(PAN.imgs[k],figy=6,ticks='off');
     print('image no:',k);