Exemplo n.º 1
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;          
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