コード例 #1
0
def run_clean_up(folder):
    debug_mode = True

    mylog = Logger("Clean up",
                   folder + "main_logfile.txt",
                   debug_mode=debug_mode)

    mylog.log("clean up for folder: ")
    mylog.log(folder)

    avg = AvgFolderMem(folder)

    subfolders = ["processed_images", "aligned_images", "correlation_images"]

    for subfolder in subfolders:
        mylog.log("Cleaned: " + subfolder)
        shutil.rmtree(avg.subfolders[subfolder])
コード例 #2
0
# py imports

# My imports
from AvgFolder_class import AvgFolderMem

# Flat Field correction manager

if __name__ == "__main__":

    # gather dark field

    pathdfh = "../../../darkfield/horizontal/"
    # average pictures

    dfh = AvgFolderMem(pathdfh)
    dfh.gather_pictures()
    dfh.c2gscale()
    dfh.squareit()
    dfh.binning(2)

    dfh.average(aligned=False, debug=True)

    dfh.save_avg()

    dfh.avg.show_image()
    plt.show()

    pathtodataset = "../../../silentcam/dataset36/"

    avg = AvgFolderMem(pathtodataset)
コード例 #3
0
def run_average_gray(folder):
    # options
    debug_mode = True

    # chose path to image sequence folder
    datasetpath = folder

    memsave = True  # True | False

    preprocop = [("convert to grayscale", ), ("square it", ), ("binning", 0),
                 ("transpose", ), ("normalize", )]

    custom_template = False  # True | False
    template_image_path = folder + "template_folder/template.png"  # path to image

    auto_template_type = "UseFirstImage"  # "Use First Image" | "Average"
    save_template = True  # True | False

    align_images = True  # True | False
    align_mode = "fixed"  # "fixed | tree" // fixed still fastest option
    align_space = (-1, 1, 0.1)  # (min angle, max angle, precision)

    # logger
    mylog = Logger("Averaging Gray",
                   datasetpath + "main_logfile.txt",
                   debug_mode=debug_mode)

    mylog.log("Debug mode: " + "ON" if debug_mode == True else "OFF")
    mylog.log("For the folder:")
    mylog.log(datasetpath)
    mylog.log("Averaging type: grey")
    mylog.log("Memory saving mode: " + str(memsave))

    mylog.log(
        "------------------------------\nLoading dataset\n------------------------------"
    )
    if memsave:
        avg = AvgFolderMem(datasetpath)
    else:
        avg = AvgFolder(datasetpath)

    avg.gather_pictures()
    # build the informatiosn
    mylog.log("number of pictures:" + str(avg.init_imgs.n))
    image = avg.init_imgs.get_image(0)
    mylog.log("Size of images: " + str(image.data.shape[0]) + "x" +
              str(image.data.shape[1]))

    mylog.log("--- Start preporcessing ---", True)

    nametofunc = {}
    nametofunc[preprocop[0]] = lambda: avg.c2gscale()
    nametofunc[preprocop[1]] = lambda: avg.squareit()
    nametofunc[preprocop[2]] = lambda n: avg.binning(n)
    nametofunc[preprocop[3]] = lambda: avg.transpose()
    nametofunc[preprocop[4]] = lambda: avg.normalize()

    for name in preprocop:
        if len(name) == 1:
            nametofunc[name]()
            mylog.log("Process: " + name[0])
        if len(name) == 2:
            nametofunc[name](name[1])
            mylog.log("Process: " + name[0] + "Arguments: " + str(name[1]))
    mylog.log("Processing took: ", True)

    mylog.log(
        "------------------------------\nGenerating template\n------------------------------"
    )

    if custom_template:
        custom_t = MyImage(template_image_path)
        custom_t.convert2grayscale()
        mylog.log("Template loaded from: " + template_image_path)
        mylog.log("Template image is: {0}x{1}".format(custom_t.get_sizex(),
                                                      custom_t.get_sizey()))
        avg.generate_template(custom_t)
    else:
        avg.generate_template(auto_template_type)
        mylog.log("Template generated: " + auto_template_type)

    mylog.log("Template generated", True)

    if save_template:
        avg.save_template()

    if debug_mode:
        avg.template.show_image()
        plt.show()
        avg.template.inspect()

    if align_images:
        mylog.log(
            "------------------------------\nAlignment\n------------------------------"
        )
        mylog.log("Choosen Aligment: " + align_mode)
        alignnames = ["min angle: ", " |max angle: ", " |precision: "]
        mylog.log("".join(a + str(d) for a, d in zip(alignnames, align_space)))
        avg.align_images(align_mode, align_space, debug_mode)
        avg.save_shifts()

        mylog.log("Alignment done", True)
        if avg.anglestree != None:
            mylog.log("Numnber of template generated: " +
                      str(len(avg.anglestree.angles_nodes)))
            mylog.log("Normally would be: " + str(
                len(np.arange(align_space[0], align_space[1], align_space[2])))
                      )
        else:
            mylog.log("Numnber of template generated: " +
                      str(avg.templaterotsft.n))
        mylog.log("Shifts saved")

        mylog.log(
            "------------------------------\nAverage\n------------------------------"
        )
        avg.average(debug=debug_mode)
        avg.save_avg()
        mylog.log("Average Complete", True)

        if debug_mode:
            avg.avg.show_image()
            plt.show()
            avg.avg.inspect()

    mylog.log("End procedure", True)
コード例 #4
0
    def __init__(self, root, path):

        # main path
        self.mpath = path

        # create main  frame
        self.mframe = Frame(root)
        self.mframe.image = {}

        self.consoleframe = Frame(self.mframe)
        self.consoleframe.grid(row=0, column=0, rowspan=2)

        # add a beauty label
        l = Label(self.consoleframe, text="Console:")
        l.grid(row=0, column=0)

        # create text box as a console
        self.constext = ConsWidget(self.consoleframe)
        self.constext.textbox.grid(row=1, column=0)

        # use the averaging class to load the images from the folder
        self.myavg = AvgFolderMem(self.mpath)
        self.myavg.gather_pictures()

        self.image_index = ConnectIndex(0)
        self.max_images = self.myavg.init_imgs.n

        titles = [
            "Initial Images", "Processed Images", "Aligned Images",
            "Corr Images"
        ]
        positions = [(0, 1), (0, 3), (0, 4), (1, 2)]
        myimgseqs = [
            self.myavg.init_imgs, self.myavg.imgs, self.myavg.algimgs,
            self.myavg.corrs
        ]
        self.canvarr = []

        for title, position, imgseq in zip(titles, positions, myimgseqs):
            frame = Frame(self.mframe)
            frame.grid(row=position[0], column=position[1])

            mycanv = ImageCanvSeq(frame, imgseq, title, (256, 256), self.myavg,
                                  self.constext)
            mycanv.frame.pack()

            self.canvarr.append(mycanv)

        # create a text box

        # give a canvas for the averaged image
        self.avgimg = Frame(self.mframe)
        self.avgimg.grid(row=0, column=5)

        myimg = ImageCanv(self.avgimg, "Average", (256, 256), self.myavg,
                          self.constext)
        myimg.cframe.grid(row=0, column=0)

        pathtoavg = self.myavg.get_avg_path()
        myimg.show_image(pathtoavg)

        # give a canvas for the template images
        self.templateimg = Frame(self.mframe)
        self.templateimg.grid(row=1, column=1)

        myimg = ImageCanv(self.templateimg, "Template", (256, 256), self.myavg,
                          self.constext)
        myimg.cframe.grid(row=0, column=0)

        pathtotemplate = self.myavg.get_template_path()
        myimg.show_image(pathtotemplate)

        # add the shift and angles

        # buttons to control images together

        bleft = Button(self.mframe, text="< conn", command=self.prev_pic)
        bleft.grid(row=2, column=1)

        bright = Button(self.mframe, text="conn >", command=self.next_pic)
        bright.grid(row=2, column=3)

        # create custom cross correlation
        # create a button analyze correlation.
        bcorr = Button(self.mframe, text="correlate", command=self.correlate)
        bcorr.grid(row=2, column=2)