def get_best_images(input_folder_real, input_folder_synthetic, num_images, output_folder): # Count the number of images that have been saved counter = 1 # Create output folder if not os.path.exists(output_folder): os.makedirs(output_folder) # Gather synthetic image paths synthetic_images = os.listdir(input_folder_synthetic) random.shuffle(synthetic_images) # Loop through synthetic images for image in synthetic_images: # Make sure image is compatible if '.html' in image: continue # Full path of real image and synthetic image current_image_path_real = join(input_folder_real, image) current_image_path_fake = join(input_folder_synthetic, image) # Load images current_image_real = image_class(current_image_path_real) current_image_fake = image_class(current_image_path_fake) # Check the number of images that have been saved if counter > num_images: return current_image_fake.save_image(join(output_folder, image)) counter += 1
def generate_more_images(input_folder, output_folder, num_images): # Counter for number of images counter = 1 os.makedirs(output_folder, exist_ok=True) # Loop through input folder list_dir = os.listdir(input_folder) for (image1, image2) in product(list_dir, list_dir): # Make sure images are different if image1 == image2: continue # Check number of images saved if counter > num_images: return # Read in the images image1_load = image_class(join(input_folder, image1)) image2_load = image_class(join(input_folder, image2)) # Combine the images result = image1_load.combine(image2_load) # Save the result dest_name = "{}__{}{}".format(image1, image2, counter) imsave(join(output_folder, dest_name), result) counter += 1
def get_stats(input_folder): # Empty lists for necessary statistics side_lengths = [] pixel_areas = [] sizes_bytes = [] # Loop through images for each in os.listdir(input_folder): # Current image current_image_path = os.path.join(input_folder, each) current_image = image_class(current_image_path) # Add in the statistics side_lengths.append(current_image.get_side_lengths()[0]) # Width side_lengths.append(current_image.get_side_lengths()[1]) # Height pixel_areas.append(current_image.get_area()) # Area sizes_bytes.append(current_image.get_size()) # Size return side_lengths, pixel_areas, sizes_bytes
sys.path.append(os.path.join(base1, 'MNIST_Load')) sys.path.append(os.path.join(base1, 'Rozell')) sys.path.append(os.path.join(base1, 'Image_Class')) os.chdir(os.path.join(base1, 'MNIST_Load')) file_path = base1 + '/Test/DB Classifier/Overnight run' dict1_path = file_path + '/orig_dict.png' dict2_path = file_path + '/trained_dict.png' dict3_path = file_path + '/trained_data.csv' write_path = file_path + '/resid_data.csv' plot_path = file_path + '/resid_plot.png' import image_class as ic ##Read image and convert to numpy array im = ic.image_class(nat_path + '\\city3.jpg') #patches = im.slice_patches() patches = im.slice_random(50) print (len(patches), patches[0].shape) ''' array.flags.writeable = True ##Set RGB to zero array[:,:,0] = 0 #R #array[:,:,1] = 0 #G array[:,:,2] = 0 #B
find_new_target = True #determines whether the antogonist should find a new target. Set to false after target is chosen. new_circle = True #determines whether the antogonist should change the circle (radius/center) it is tracking #logical to choose motion move_in_circle = False #Create a display surface screen = pygame.display.set_mode(SCREEN_SIZE,0,32) #Returns a surface object (the window) pygame.display.set_caption("Grass Adventures") #Create background and rescale the image size background = pygame.image.load('grass_sideview.jpg').convert() background_size = background.get_size() background = pygame.transform.scale(background,(int(2*background_size[0]),int(2*background_size[1]))) #Get picture of Mittens Mittens_image = image_class.image_class('Mittens.png',0.1,[100,100]) Sunny_image = image_class.image_class('Sunny_Snow.png',0.45,[300,300]) #Create lists of flower and animal images flower_list = [] hyacinth_image = image_class.image_class('hyacinths.png',0.1,[200,200]) lily_image = image_class.image_class('lilyplant.png',0.5,[500,500]) callalily_image = image_class.image_class('callalily.png',0.5,[700,200]) flower_list.append(hyacinth_image) flower_list.append(lily_image) flower_list.append(callalily_image) animal_list = [] bunny_image = image_class.image_class('babybunny.png',0.4,[200,600]) bluebird_image = image_class.image_class('bluebird.png',0.4,[700,100]) animal_list.append(bunny_image)
fpr0=[] fpr1=[] fnr0=[] fnr1=[] sp0=[] sp1=[] recall0=[] recall1=[] recall_av=[] presicion0=[] presicion1=[] presicion_av=[] img_class=image_class(test_CTs,test_GTVs,test_Torso,test_penalize ,bunch_of_images_no=20,is_training=1,patch_window=ct_cube_size,gtv_patch_window=gtv_cube_size ) for img_indx in range(1,len(test_CTs)): print('img_indx:%s' %(img_indx)) ss = str(test_CTs[img_indx]).split("/") name = ss[8] + '_' + ss[9] name = (ss[8] + '_' + ss[9] + '_' + ss[10].split('%')[0]).split('_CT')[0] [CT_image, GTV_image, Torso_image, volume_depth, voxel_size, origin, direction] = _rd.read_image_seg_volume(test_CTs, test_GTVs, test_Torso, img_indx, ct_cube_size, gtv_cube_size)
dict1_path = file_path + '/orig_dict.png' dict2_path = file_path + '/trained_dict.png' dict3_path = file_path + '/trained_data.csv' write_path = file_path + '/resid_data.csv' plot_path = file_path + '/resid_plot.png' nat_path = base1 + '/Rozell/Natural_images' import mnist_load as mnist import r_network_class as Lca_jack import image_class as ic num_rfields = 50 num_patches = 3000 im_dims = (8,8,3) #Patch shape nat_image = ic.image_class(nat_path + '/' + 'city2.jpg') ## Get patches and set Lca variables training_data = nat_image.slice_patches()[:num_patches] random.shuffle(training_data) X = np.zeros((num_patches, np.product(im_dims))) for i in range(len(training_data)): X[i, :] = training_data[i].flatten() net = Lca(num_rfields, tAlpha=0.8, tLambda=1.0) net.init(np.product(im_dims),num_rfields) ## Use my Lca class to save pre dictionary before = np.array(np.array(net._crossbar.copy())) d1 = Lca_jack.r_network(np.array(net._crossbar)) d1.set_dim(im_dims) d1.save_dictionary(5, 10, dict1_path)
# Changing image dimensions compress = args.compress # Change image brightness brightness = args.increase_brightness os.makedirs(args.output_folder, exist_ok=True) for each in os.listdir(args.input_folder): if args.no_filter_dups is False and "dup" in each: continue if each.startswith(.) or each.endswith('.html'): continue filepath = os.path.join(args.input_folder, each) current_image = image_class(filepath) if compress is True: current_image.compress(args.compression_factor) if brightness is True: current_image.increase_brightness(75) if add_AtoB is True: # For real images # This output path is specific to our project, if you are using # our code you should specify your own paths output_path = os.path.join( args.output_folder, "AtoB_{}.jpg".format(splitext(each)[0])) imsave(output_path, current_image.get_image()) else: # For fake images # This output path is specific to our project, if you are using