Beispiel #1
0
 def frame_uncompress(self, c_frame, inplace = True):
     data = np.zeros(c_frame.size,dtype)
     wave = wv.wavelet2D(data,c_frame.decomp_level)
     comp_manager = cp.SPIHT(wave)
     if inplace:
         comp_manager.output_stream = c_frame.payload
     else:
         comp_manager.output_stream = list(c_frame)
     comp_manager.n = c_frame.max_n
     comp_manager.uncompress()
     return comp_manager
Beispiel #2
0
 def init(self):
     N = self.wavelet.rows * self.wavelet.cols
     self.LSP = deque([])
     rows = self.wavelet.rows / 2 ** (self.wavelet.level-1)
     cols = self.wavelet.cols / 2 ** (self.wavelet.level-1)
     self.LIP = wv.get_morton_order(rows*cols)
     self.LIS = wv.get_morton_order(rows*cols/4,rows*cols)
     for i in self.LIS:
         i.entry_type = "A"
     self.test_data = wv.wavelet2D(np.zeros((512,512)),self.wavelet.level)
     return
Beispiel #3
0
def cdf53(signal, level = 1, in_place = True):
    if not isinstance(signal, np.ndarray) or signal.ndim != 2:
        raise TypeError, "Signal expected as 2D ndarray (numpy)"
    if not in_place:
        signal = signal.copy()
    if signal.dtype == np.uint8:
        sig_i8 = np.zeros((len(signal),2*len(signal[0])),np.uint8)
        sig_i8[:,0:-1:2] = signal
        sig_i16 = sig_i8.view(np.uint16)
        sig_f16 = sig_i16.view(np.float16)
        sig_f16[:] = sig_i16
        signal = sig_f16
    signal = normal_forward(signal,level,math.sqrt(2),(-0.5,0.25))
    return wv.wavelet2D(signal,level,"cdf53")
Beispiel #4
0
def cdf97(signal, level = 1,  in_place = True):
    if not isinstance(signal, np.ndarray) or signal.ndim != 2:
        raise TypeError, "Signal expected as 2D ndarray (numpy)"
    if not in_place:
        signal = signal.copy()
    if signal.dtype == np.uint8:
        sig_i8 = np.zeros((len(signal),4*len(signal[0])),np.uint8)
        sig_i8[:,0:-1:4] = signal
        sig_i16 = sig_i8.view(np.uint32)
        sig_f16 = sig_i16.view(np.float32)
        sig_f16[:] = sig_i16
        signal = sig_f16
    signal = normal_forward(signal,level,1/1.149604398,(-1.586134342,-0.05298011854,0.8829110762,0.4435068522))
    return wv.wavelet2D(signal,level,"cdf97")
Beispiel #5
0
 def expand(self, stream, width, height, level, wise_bit, bpp, lbpp,
            f_center, alpha, c, gamma):
     self.Lbpp = bpp
     self.lbpp = lbpp
     self.alpha = alpha
     self.P = f_center
     self.c = c
     self.wv = wvt.wavelet2D(np.zeros((width, height), dtype=Int), level)
     self.dt = self.wv.data
     self.wv.level = level
     self.gamma = gamma
     self.calculate_fovea_length()
     return super(fv_speck, self).expand(stream, width, height, level,
                                         wise_bit)
Beispiel #6
0
def pack_wave_coeff(coeff):
    mtx = np.zeros((2 * len(coeff[-1][0]), 2 * len(coeff[-1][0][0])))
    rw = len(coeff[0])
    cl = len(coeff[0][0])
    mtx[:rw, :cl] = coeff[0].copy()
    y = rw
    x = cl
    for i in range(1, len(coeff)):
        rw = len(coeff[i][0])
        cl = len(coeff[i][0][0])
        mtx[:rw, x : x + cl] = coeff[i][0].copy()
        mtx[y : y + rw, :cl] = coeff[i][1].copy()
        mtx[y : y + rw, x : x + cl] = coeff[i][2].copy()
        y += rw
        x += cl
    wavelet = wv.wavelet2D(mtx, len(coeff) - 1)
    return wavelet
Beispiel #7
0
 def iInitialization(self, width, height, level, wise_bit):
     self.wv = wvt.wavelet2D(np.zeros((width, height), dtype=Int), level)
     self.dt = self.wv.data
     self.wv.level = level
     X = wvt.get_z_order(self.wv.rows * self.wv.cols)
     self.LIS = ts.CircularStack(self.wv.cols * self.wv.rows)
     self.nextLIS = ts.CircularStack(self.wv.cols * self.wv.rows)
     self.LSP = ts.CircularStack(self.wv.cols * self.wv.rows)
     s_size = (self.wv.rows * self.wv.cols / 2 ** (2 * self.wv.level))
     self.S = X[:s_size]
     del X[:s_size]
     self.I = X
     self.n = wise_bit
     self.LIS.push(self.S)
     self.i_partition_size = (self.wv.rows / 2 ** self.wv.level) ** 2
     self._idx = 0
     self._logidx = 0
Beispiel #8
0
def fvht_unpack(frame, display_progress=True, str_pr = "",d = {}, handle = True):
    """De-compresses a wavelet with SPIHT.

    Runs the original SPIHT algorithm from Dr. Pearlsman paper over the 
    given wavelet.

    Args:
        frame: A previously compressed frame
        display_progress: True if you want to print on screen algorithm 
                    progress

    Returns:
        An uncompressed wavelet2D instance 
    """
    #filename = str(frame["rows"]) + "x" + str(frame["cols"]) + "_" + str(frame["decomp_level"]) +".dol" 
    #if not d:
    #    try:
    #        f = open(filename,"r")
    #        d = pickle.load(f)
    #        f.close()
    #        handle = True
    #    except IOError as e:
    #        d = {}
    #        handle = True
    #update = len(d)
    codec = FVHT()
    data = np.zeros((frame["rows"],frame["cols"]),np.int32)
    codec.wavelet = wv.wavelet2D(data,frame["decomp_level"],frame["wave_type"])
    codec.bpp = frame["Lbpp"]
    codec.delta = frame["quant_delta"]
    codec.str_pr = str_pr
    codec.n = frame["wise_bit"]
    codec.d_memory = d
    codec.output_stream = deque(frame["payload"])
    codec.Lbpp = frame["Lbpp"]
    codec.lbpp = frame["lbpp"]
    codec.alpha = frame["alpha"]
    codec.c = frame["c"]
    codec.gamma = frame["gamma"]
    codec.P = frame["fovea_center"]
    codec.uncompress()
    #if len(codec.d_memory) > update and handle:
    #    f = open(filename,"w+")
    #    pickle.dump(codec.d_memory,f)
    #    f.close()
    return codec.wavelet