def run_create_test_dataset(folder): debug_mode = True # set parameters testdatasetpath = folder mypicname = "./data/Lenna.png" n_pictures = 25 min_a = -10 max_a = 10 min_xs = -25 max_xs = 25 min_ys = -25 max_ys = 25 flip_angle = True mylog = Logger("Create gray dataset", testdatasetpath + "main_logfile.txt", debug_mode=debug_mode) mylog.log("Creating dataset in:\n" + testdatasetpath) mylog.log("Using the picture: " + mypicname) mylog.log("Creating dataset with {0} pictures".format(n_pictures)) mylog.log("With rotations from {0} to {1} degree".format(min_a, max_a)) mylog.log("With shift in x: from {0} to {1} and y: from {2} to {3}".format( min_xs, max_xs, min_ys, max_ys)) mylog.log( "The dataset will be generated by {0} randomly flipping rotations and translations" .format("" if flip_angle == True else "not")) if not isdir(testdatasetpath): mkdir(testdatasetpath) mylog.log("Created test dataset path") # create a test dataset: mypic = MyImage(mypicname) mypic.squareit() mypic.convert2grayscale() mypic.binning(2) mypic.normalize() mylog.log("Processing done") template_folder = join(testdatasetpath, "template_folder") if not isdir(template_folder): mkdir(template_folder) mypic.save(join(template_folder, "template.png")) mylog.log("Saved the original image in the template folder") if debug_mode: mypic.show_image() plt.show() mylog.log( "------------------------------\nCreating dataset\n------------------------------" ) np.random.seed(10) logpathdir = join(testdatasetpath, "tlog") if not isdir(logpathdir): mkdir(logpathdir) with open(join(logpathdir, "mytransformations.log"), 'w') as f: angles = np.random.uniform(min_a, max_a, n_pictures) for i in range(n_pictures): image = deepcopy(mypic) if flip_angle: anglefirst = False if np.random.randint(0, 2) == 0 else True else: anglefirst = True angle = angles[i] dx = np.random.randint(min_xs, max_xs) dy = np.random.randint(min_ys, max_ys) f.write("{0} {1} {2} {3}\n".format(anglefirst, dx, dy, angle)) mylog.log( "Pictrue with: rot first {0}, angle: {1}, shift x: {2}, y: {3} created" .format(anglefirst, angle, dx, dy)) if anglefirst: image.rotate(angle) image.move(dx, dy) else: image.move(dx, dy) image.rotate(angle) if debug_mode: image.show_image() plt.show() image.save(join(testdatasetpath, "pic_" + str(i) + ".png"))
imagepath = "../../../Lenna.png" # # convert range test # x = np.arange(0, 3, 0.1) # print(x) # # for i in x: # print(i, map_range(i, 0, 1, 0, 2*np.pi)) im = MyImage() im.read_from_file(imagepath) im.convert2grayscale() print("Original image") im.show_image() plt.show() ft = ImgFFT(im) ft.ft() imres = ft.resize_image(256, 256) imres.show_image() plt.show() # print("Power Spectrum") # ps = ft.power_spectrum() # ps.show_image() # plt.show() # # real = ft.get_real_part()