Beispiel #1
0
    def _initialize_border(self, piximage):
        
        img_matrix = piximage.image_ycrcb
    
        coeff_n = VARIABLE['coefficients_number']
    
        blockH = VARIABLE['block_height']
        blockW = VARIABLE['block_width']

        imgH, imgW = np.array(np.shape(img_matrix)[:2])
        
        overlapH = VARIABLE['overlap_vertical']
        overlapW = VARIABLE['overlap_horizontal']

        numBlockH = int( (imgH-blockH)/(blockH-overlapH) ) + 1
        numBlockW = int( (imgW-blockW)/(blockW-overlapW) ) + 1
    
        img_r_matrix = np.array(img_matrix[:,:,0], np.float32)
        img_g_matrix = np.array(img_matrix[:,:,1], np.float32)
        img_b_matrix = np.array(img_matrix[:,:,2], np.float32)
    
        data_bgr = [ ]
        for row in range(numBlockH):
            bgr = []
            for col in range(numBlockW):
                row_start, col_start = [ row*(blockW-overlapW), col*(blockH-overlapH)]
                row_end, col_end = [ row_start+blockW, col_start+blockH ] 
             
             
                bgr.append( zigzag( cv2.dct(img_b_matrix[row_start:row_end, col_start:col_end]), coeff_n ) )
                bgr.append( zigzag( cv2.dct(img_g_matrix[row_start:row_end, col_start:col_end]), coeff_n ) )
                bgr.append( zigzag( cv2.dct(img_r_matrix[row_start:row_end, col_start:col_end]), coeff_n ) )
                
            data_bgr.append(bgr)
            
        data_bgr = np.reshape( np.array(data_bgr), (numBlockH, numBlockW, 3, coeff_n) )
       
        self.data_bgr = data_bgr
        
        ss_positions, s_positions = piximage.border_positions
        
        self.N_border = { }
        for key, ss_item in ss_positions.items():
            s_item = s_positions[key]
            
            blockHpos =  [ numpy.ceil( (ss_item[0]-blockH)/(blockH-overlapH) ) + 1, int( (ss_item[1]-blockH)/(blockH-overlapH) ) + 1 ]
            blockWpos = [ numpy.ceil( (s_item[0]-blockW)/(blockW-overlapW) ) + 1, int( (s_item[1]-blockW)/(blockW-overlapW) ) + 1 ]
            self.N_border[key] = [blockHpos, blockWpos]
        
        self.N_border = OrderedDict(sorted(self.N_border.items(), key=lambda t: t[1][0][0]))
        self.data_bgr_splitted = split_border( data_bgr, self.N_border )
Beispiel #2
0
    def _initialize(self, img_matrix):
     
        coeff_n = VARIABLE['coefficients_number']
    
        blockH = VARIABLE['block_height']
        blockW = VARIABLE['block_width']

        imgH, imgW = np.array(np.shape(img_matrix)[:2])
        
        overlapH = VARIABLE['overlap_vertical']
        overlapW = VARIABLE['overlap_horizontal']

        numBlockH = int( (imgH-blockH)/(blockH-overlapH) ) + 1
        numBlockW = int( (imgW-blockW)/(blockW-overlapW) ) + 1
    
        
        img_r_matrix = np.array(img_matrix[:,:,0], np.float32)
        img_g_matrix = np.array(img_matrix[:,:,1], np.float32)
        img_b_matrix = np.array(img_matrix[:,:,2], np.float32)
    
        data_bgr = [ ]
        for row in range(numBlockH):
            bgr = []
            for col in range(numBlockW):
                row_start, col_start = [ row*(blockW-overlapW), col*(blockH-overlapH)]
                row_end, col_end = [ row_start+blockW, col_start+blockH ] 
             
             
                bgr.append( zigzag( cv2.dct(img_b_matrix[row_start:row_end, col_start:col_end]), coeff_n ) )
                bgr.append( zigzag( cv2.dct(img_g_matrix[row_start:row_end, col_start:col_end]), coeff_n ) )
                bgr.append( zigzag( cv2.dct(img_r_matrix[row_start:row_end, col_start:col_end]), coeff_n ) )
                
            data_bgr.append(bgr)
            
        data_bgr = np.reshape( np.array(data_bgr), (numBlockH, numBlockW, 3, coeff_n) )
       
        self.data_bgr = data_bgr
        self.data_bgr_splitted = split( data_bgr, self.N )