Пример #1
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)
Пример #2
0
# 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)
    avg.gather_pictures()
    avg.c2gscale()
    avg.squareit()
    avg.binning(2)

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