def align_images(self, angle_space_mode, angle_space, debug=False):
        ''' The function takes a serie of images and aligns it against the
        template, outputs the resulting images into the aligned_images folder
        input:
          angle_space_mode = ("fixed"|"tree")
          angle_space = tuple (min angle, max angle, precision)
        '''
        c = 0
        if angle_space_mode == "fixed":
            self.generate_rotref(angle_space)
        elif angle_space_mode == "tree":
            self.anglestree = AnglesTree(angle_space, self.template)

        for image in self.imgs:

            if angle_space_mode == "fixed":
                # generate the fourier transform of the image
                imgft = ImgFFT(image)
                imgft.ft()

                # calculate the rotations
                smax = 0
                idxmax = 0
                for idx, temp in enumerate(self.templaterotsft):
                    corr = temp.correlate(imgft)
                    s, dx, dy = corr.find_peak(1)

                    if s > smax:
                        smax = s
                        idxmax = idx

                angle = float(self.angles_list[idxmax])
            elif angle_space_mode == "tree":
                angle = self.anglestree.analyze_image(image)

            print("angle found", angle)

            rotalgimage = deepcopy(image)
            rotalgimage.rotate(-angle)

            # calculate the shifts
            rotalgimageft = ImgFFT(rotalgimage)
            rotalgimageft.ft()

            corr = rotalgimageft.correlate(self.templateft)
            self.corrs.set_image(c, corr)

            dx, dy = corr.find_translation(1)
            self.shifts.append((dx, dy, angle))

            print("shifts:", dx, dy)

            rotalgimage.move(dx, dy)

            self.algimgs.set_image(c, rotalgimage)

            if debug:
                print("Correlated image:", c)

            c += 1
Beispiel #2
0
    def align_images(self, debug=False):
        c = 0

        anglestree = AnglesTree(-1, 1, 0.1, self.template)

        for image in self.imgs:

            angle = anglestree.analyze_image(image)

            #            # generate the fourier transform of the image
            #            imgft = ImgFFT(image)
            #            imgft.ft()
            #
            #            # calculate the rotations
            #            smax = 0
            #            idxmax = 0
            #            for idx, temp in enumerate(self.templaterotsft):
            #                corr = temp.correlate(imgft)
            #                s, dx, dy = corr.find_peak(1)
            #
            #                if s > smax:
            #                    smax = s
            #                    idxmax = idx
            #
            #            angle = float(self.angles_list[idxmax])

            print("angle found", angle)

            rotalgimage = deepcopy(image)
            rotalgimage.rotate(-angle)

            # calculate the shifts
            rotalgimageft = ImgFFT(rotalgimage)
            rotalgimageft.ft()

            corr = rotalgimageft.correlate(self.templateft)
            self.corrs.set_image(c, corr)

            dx, dy = corr.find_translation(1)
            self.shifts.append((dx, dy, angle))

            print("shifts:", dx, dy)

            rotalgimage.move(dx, dy)

            self.algimgs.set_image(c, rotalgimage)

            if debug:
                print("Correlated image:", c)

            lg.info("correlated image n: " + str(c))

            c += 1
Beispiel #3
0
    def align_images(self, debug=False):
        c = 0
        for image in self.imgs:

            # generate the fourier transform of the image
            imgft = ImgFFT(image)
            imgft.ft()

            # calculate the rotations
            smax = 0
            idxmax = 0
            for idx, temp in enumerate(self.templaterotsft):
                corr = temp.correlate(imgft)
                s, dx, dy = corr.find_peak(1)

                if s > smax:
                    smax = s
                    idxmax = idx

            print("angle found", self.angles_list[idxmax])

            rotalgimage = deepcopy(image)
            rotalgimage.rotate(-self.angles_list[idxmax])

            # calculate the shifts
            rotalgimageft = ImgFFT(rotalgimage)
            rotalgimageft.ft()

            corr = rotalgimageft.correlate(self.templateft)
            self.corrs.append(corr)

            dx, dy = corr.find_translation(1)
            self.shifts.append((dx, dy))

            print("shifts:", dx, dy)

            rotalgimage.move(dx, dy)
            self.algimgs.append(rotalgimage)

            if debug:
                print("Correlated image:", c)
            lg.info("correlated image n: " + str(c))

            c += 1