def forward(self, prefix = "/tmp/", N=5, T=2): '''A Motion Compensated Discrete Wavelet Transform. Compute the MC 1D-DWT. The input video (as a sequence of 1-levels decompositions) must be stored in disk in the directory <prefix>, and the output (as a 1-levels MC decompositions) will generated in the same directory. Input ----- prefix : str Localization of the input/output images. Example: "/tmp/". N : int Number of decompositions to process. T : int Number of levels of the MCDWT (temporal scales). Controls the GOP size. T | GOP_size ----+----------- 0 | 1 1 | 2 2 | 4 3 | 8 4 | 16 5 | 32 : | : P : int Predictor to use: 1 --> Average Predictor. 2 --> Weighted Average Predictor. Returns ------- None. ''' x = 2 for t in range(T): # Temporal scale i = 0 aL, aH = decomposition.read(prefix, "{:03d}".format(0)) while i < (N//x): bL, bH = decomposition.read(prefix, "{:03d}".format(x*i+x//2)) cL, cH = decomposition.read(prefix, "{:03d}".format(x*i+x)) bH = self.__forward_butterfly(aL, aH, bL, bH, cL, cH) decomposition.writeH(bH, prefix, "{:03d}".format(x*i+x//2)) aL, aH = cL, cH i += 1 x *= 2
def forward(self, prefix="/tmp/", N=5, T=2): '''Forward MCOLP. Compute a MC 1D-DWT, estimating in the L subbands and compensaing in the H subbands of the Orthogonal Laplacian Pyramid. The input video (as a sequence of 1-iteration decompositions) must be stored in disk in the directory <prefix>, and the output (as a 1-iteration MC decompositions) will generated in the same directory. Input ----- prefix : str Localization of the input/output images. Example: "/tmp/". N : int Number of decompositions to process. T : int Number of iterations of the MCOLP (temporal scales). Controls the GOP size. T | GOP_size ----+---------- 0 | 1 1 | 2 2 | 4 3 | 8 4 | 16 5 | 32 : | : Returns ------- The output motion compensated decompositions. ''' x = 2 for t in range(T): # Temporal scale #print("a={}".format(0), end=' ') i = 0 aL, aH = decomposition.read(prefix, "{:03d}".format(0)) while i < (N // x): #print("b={} c={}".format(x*i+x//2, x*i+x)) bL, bH = decomposition.read(prefix, "{:03d}".format(x * i + x // 2)) cL, cH = decomposition.read(prefix, "{:03d}".format(x * i + x)) residue_bH = self.__forward_butterfly(aL, aH, bL, bH, cL, cH) decomposition.writeH(residue_bH, prefix, "{:03d}".format(x * i + x // 2)) aL, aH = cL, cH #print("a={}".format(x*i+x), end=' ') i += 1 x *= 2
def forward(self, prefix="/tmp/", N=5, I=2): '''Forward MCDWT. Compute the MC 1D-DWT. The input video (as a sequence of 1-iteration decompositions) must be stored in disk in the directory <prefix>, and the output (as a 1-iteration MC decompositions) will generated in the same directory. Input ----- prefix : str Localization of the input/output images. Example: "/tmp/". N : int Number of decompositions to process. I : int Number of iterations of the MCDWT (temporal scales). Controls the GOP size. I | GOP_size ----+---------- 0 | 1 1 | 2 2 | 4 3 | 8 4 | 16 5 | 32 : | : Returns ------- The output motion compensated decompositions. ''' x = 2 for t in range(I): # Temporal scale i = 0 aL, aH = decomposition.read(prefix, "{:03d}".format(0)) while i < (N // x): bL, bH = decomposition.read(prefix, "{:03d}".format(x * i + x // 2)) cL, cH = decomposition.read(prefix, "{:03d}".format(x * i + x)) residue_bH = self.__forward_butterfly(aL, aH, bL, bH, cL, cH) decomposition.writeH(residue_bH, prefix, "{:03d}".format(x * i + x // 2)) aL, aH = cL, cH i += 1 x *= 2
def backward(self, prefix = "/tmp/", N=5, T=2): x = 2**T for t in range(T): # Temporal scale i = 0 aL, aH = decomposition.read(prefix, "{:03d}".format(0)) while i < (N//x): bL, bH = decomposition.read(prefix, "{:03d}".format(x*i+x//2)) cL, cH = decomposition.read(prefix, "{:03d}".format(x*i+x)) bH = self.__backward_butterfly(aL, aH, bL, bH, cL, cH) decomposition.writeH(bH, "{:03d}".format(x*i+x//2)) aL, aH = cL, cH i += 1 x //=2
def backward(self, prefix="/tmp/", N=5, T=2): '''Backward MCDWT. Compute the inverse MC 1D-DWT. The input sequence of 1-iteration MC decompositions must be stored in disk in the directory <prefix>, and the output (as a 1-iteration decompositions) will generated in the same directory. Input ----- prefix : str Localization of the input/output images. Example: "/tmp/". N : int Number of decompositions to process. T : int Number of iterations of the MCDWT (temporal scales). Returns ------- The sequence of 1-iteration decompositions. ''' x = 2**T for t in range(T): # Temporal scale i = 0 aL, aH = decomposition.read(prefix, "{:03d}".format(0)) while i < (N // x): bL, residue_bH = decomposition.read( prefix, "{:03d}".format(x * i + x // 2)) cL, cH = decomposition.read(prefix, "{:03d}".format(x * i + x)) bH = self.__backward_butterfly(aL, aH, bL, residue_bH, cL, cH) decomposition.writeH(bH, prefix, "{:03d}".format(x * i + x // 2)) aL, aH = cL, cH i += 1 x //= 2
'''MODIFICA LA SUBBANDA HH PONIENDOLA EN NEGRO CON UN PUNTO BLANCO EN EL CENTRO''' for i in range(args.N): LH, HL, HH = decomposition.readH("{}{:03d}".format(args.decompositions, i)) LL = decomposition.readL("{}{:03d}".format(args.decompositions, i)) y = math.ceil(HH.shape[0]/2) x = math.ceil(HH.shape[1]/2) HH = HH * 0 HH[x][y][0] = 255 HH[x][y][1] = 255 HH[x][y][2] = 255 decomposition.writeH([LH,HL,HH],"{}{:03d}".format(args.decompositions, i)) '''SE RECONSTRUYE LA IMAGEN Y SE VUELVE A DESCOMPONERLA''' d.backward(args.decompositions, '/tmp/recons_MDWT_', args.N) d.forward('/tmp/recons_MDWT_', args.decompositions, args.N) for i in range(args.N): print("ESPACIAL NIVEL {}\n" "********\n".format(i)) LH, HL, HH = decomposition.readH("{}{:03d}".format(args.decompositions, i)) LL = decomposition.readL("{}{:03d}".format(args.decompositions, i)) path += '/LL/'