Exemple #1
0
    def backward(self, S="/tmp/stockholm_", s="/tmp/stockholm_", N=5):
        ''' Motion 1-iteration forward 2D DWT of a sequence of decompositions.

        Compute the inverse 2D-DWT of each decomposition of the sequence S.

        Input:
        -----

            S: the sequence of decompositions to be transformed.

        Output:
        ------

            s: the sequence of images.

        '''

        for i in range(N):
            pyr = decomposition.read("{}{:03d}".format(S, i))
            img = self.dwt.backward(pyr)
            image.write(img, "{}{:03d}".format(s, i))
Exemple #2
0
    def backward(self, prefix="/tmp/", N=5):
        '''Motion 1-iteration forward 2D DWT of a sequence of decompositions.

        Compute the inverse 2D-DWT of each decomposition of the
        sequence of decompositions placed at <prefix>.

        Input:
        -----

            prefix: the sequence of decompositions to be transformed.
            N: the number of decompositions.

        Output:
        ------

            (disk): the sequence of images.

        '''

        for i in range(N):
            pyr = decomposition.read(prefix, "{:03d}".format(i))
            img = self.dwt.backward(pyr)
            image.write(img, prefix, "{:03d}".format(i))
Exemple #3
0
                        "--index",
                        help="Index of the image/decomposition",
                        default="000")
    parser.add_argument("-w",
                        "--wavelet",
                        help="Wavelet name",
                        default="bior3.5")
    parser.add_argument("-s",
                        "--show",
                        action='store_true',
                        help="Show available wavelet names")

    args = parser.parse_args()
    dwt = DWT(wavelet=args.wavelet)

    if args.show:
        dwt.show()
    else:
        if args.backward:
            if __debug__:
                print("Backward transform")
            d = decomposition.read(args.prefix, args.index)
            i = dwt.backward(d)
            image.write(i, args.prefix, args.index)
        else:
            if __debug__:
                print("Forward transform")
            i = image.read(args.prefix, args.index)
            d = dwt.forward(i)
            decomposition.write(d, args.prefix, args.index)
Exemple #4
0
    def forward_(prefix = "/tmp/", N = 5, K = 2):
        '''A Motion Compensated Discrete Wavelet Transform.

        Compute the MC 1D-DWT. The input video (as a sequence of images)
        must be stored in disk (<input> directory) and the output (as a
        sequence of DWT coefficients that are called pyramids) will be
        stored in disk (<output> directory).

        Arguments
        ---------

            prefix : str

                Localization of the input/output images. Example:
                "/tmp/".

             N : int

                Number of images to process.

             K : int

                Number of levels of the MCDWT (temporal scales). Controls
                the GOP size. 

                  K | GOP_size
                ----+-----------
                  0 |        1
                  1 |        2
                  2 |        4
                  3 |        8
                  4 |       16
                  5 |       32
                  : |        :

        Returns
        -------

            None.

        '''

        # import ipdb; ipdb.set_trace()
        #k = 0
        for k in range(K): # spatial scale
            x = 2
            while x < N:
                i = 0 # first image of the butterfly
                A = image.read("{}{:03d}_{}".format(prefix, i, k))
                dwtA = dwt.forward(A)
                L_y = dwtA[0].shape[0]
                L_x = dwtA[0].shape[1]
                pyramid.write(dwtA, "{}{:03d}_{}".format(prefix, i, k+1))
                zero_L = np.zeros(dwtA[0].shape, np.float64)
                zero_H = (zero_L, zero_L, zero_L)
                AL = dwt.backward(dwtA[0], zero_H)
                if __debug__:
                    image.write(AL, "{}{:03d}_{}".format(prefix + "_AL_", i, k))
                AH = dwt.backward(zero_L, dwtA[1])
                if __debug__:
                    image.write(AH, "{}{:03d}_{}".format(prefix + "_AH_", i, k))
                while i < (N//x):
                    print("k={} i={} x={} B={} C={}".format(k, i, x, x*i+x//2, x*i+x))
                    B = image.read("{}{:03d}_{}".format(prefix, x*i+x//2, k))
                    dwtB = dwt.forward(B)
                    BL = dwt.backward(dwtB[0], zero_H)
                    BH = dwt.backward(zero_L, dwtB[1])
                    C = image.read("{}{:03d}_{}".format(prefix, x*i+x, k))
                    dwtC = dwt.forward(C)
                    pyramid.write(dwtC, "{}{:03d}_{}".format(prefix, x*i+x, k+1))
                    CL = dwt.backward(dwtC[0], zero_H)
                    if __debug__:
                        image.write(CL, "{}{:03d}_{}".format(prefix + "_CL_", x*i+x, k))
                    CH = dwt.backward(zero_L, dwtC[1])
                    if __debug__:
                        image.write(CH, "{}{:03d}_{}".format(prefix + "_CH_", x*i+x, k))

                    if __debug__:
                        BLA = motion_compensation(AL, BL, AL)
                        BLC = motion_compensation(CL, BL, CL)
                        prediction = (BLA+BLC) / 2
                        image.write(prediction, "{}{:03d}_{}".format(prefix + "_prediction_L_", x*i+x//2, k))

                    BHA = motion_compensation(AL, BL, AH)
                    BHC = motion_compensation(CL, BL, CH)
                    if __debug__:
                        image.write(BH, "{}{:03d}_{}".format(prefix + "_BH_", x*i+x//2, k))
                    prediction = (BHA + BHC) / 2
                    if __debug__:
                        image.write(prediction, "{}{:03d}_{}".format(prefix + "_prediction_", x*i+x//2, k))
                    rBH = BH - prediction
                    if __debug__:
                        image.write(rBH, "{}{:03d}_{}".format(prefix + "_residue_", x*i+x//2, k))
                    rBH = dwt.forward(rBH)
                    rBH[0][0:L_y,0:L_x,:] = dwtB[0]
                    pyramid.write(rBH, "{}{:03d}_{}".format(prefix, x*i+x//2, k+1))
                    AL = CL
                    AH = CH
                    i += 1
                x *= 2
Exemple #5
0
                        "--image",
                        help="Image to be transformed",
                        default="/tmp/stockholm/000")

    parser.add_argument("-d",
                        "--decomposition",
                        help="Decomposition to be transformed",
                        default="/tmp/stockholm_000")

    args = parser.parse_args()

    dwt = DWT()
    if args.backward:
        if __debug__:
            print("Backward transform")
        d = decomposition.read("{}".format(args.decomposition))
        i = dwt.backward(d)
        #i = np.rint(i)
        image.write(i, "{}".format(args.image))
    else:
        if __debug__:
            print("Forward transform")
        i = image.read("{}".format(args.image))
        d = dwt.forward(i)
        #LL = np.rint(d[0])
        #LH = np.rint(d[1][0])
        #HL = np.rint(d[1][1])
        #HH = np.rint(d[1][2])
        #decomposition.write((LL, (LH, HL, HH)), "{}".format(args.decomposition))
        decomposition.write(d, "{}".format(args.decomposition))