def take_snapshot(img, iteration_step=0): """ Given image and iteration_step, saves 'image' concatenated with 'iteration_step'. This function is ONLY for debug purposes. """ folder_name = "./Output/" filename = "image_isodata" + "_" + str(iteration_step) img_eq = equalization_using_histogram(img) save_image(folder_name, filename, img_eq)
def export_image_layer(self, layer_name, filename, path_to): """ Export an image file for a given layer to the given path. """ layer = self._get_layer_securely(layer_name) img_matrix = equalization_using_histogram(layer) save_image(path_to, filename, img_matrix)
def test_all(self): image_path = os.path.join(IMAGES, "DAT_01.001") print image_path dataset = create_dataset_from_path(image_path) band = get_band_from_dataset(dataset) geoinfo = get_geoinfo(dataset, cast_to_int=True) xoff = geoinfo['xoff'] + 2000 yoff = geoinfo['yoff'] + 2000 ## Parameters: win_xsize = 100 # window size in coord x win_ysize = 100 # window size in coord y k = 1 # parameter of frost filter, ex: k=1 or k=10 or k=100 win_size = 3 # size of the window for the filter function damping_factor = 1 # parameter of frost filter, ex: 1 or 10 or 1000 image = read_image_from_band(band, xoff, yoff, win_xsize, win_ysize) # Try K-Means kmean_timer = Timer() n_classes = 8 iterations = 1000 class_image = kmeans_classification(image, n_classes, iterations) kmean_timer.stop_timer() kmean_timer.calculate_time_elapsed(print_value=True) # Try Isodata isodata_timer = Timer() parameters={"K": 8, "I":1000} class_image = isodata_classification(image,parameters=parameters ) isodata_timer.stop_timer() isodata_timer.calculate_time_elapsed(print_value=True) numerito = parameters["K"] # Try the filters filter_timer = Timer() numerito = 11 cucito = 0.30 image_filtered = mean_filter(image, win_size=numerito) image_filtered = median_filter(image,win_size) image_filtered = frost_filter(image, damping_factor=1.0, win_size=11) image_filtered = kuan_filter(image, win_size=7, cu=1.0) image_filtered = lee_filter(image, win_size=numerito, cu=cucito) image_filtered = lee_enhanced_filter(image, win_size=numerito, cu=cucito) filter_timer.stop_timer() diff = filter_timer.calculate_time_elapsed(print_value=True) # Frost y K-Means ventana = 7 damp = 1.0 # parameters={"K" : 5, "I" : 100} # _timer = Timer() # image_filtered = frost_filter(image, damping_factor=damp, win_size=ventana) class_image = isodata_classification(image_filtered, parameters) # # _timer.stop_timer() _timer.calculate_time_elapsed(print_value=True) # image_corrected = equalization_using_histogram(class_image) save_image(IMG_DEST_DIR, "image_" + str(ventana) + "frostisodata" + str(damp) + "c" + str(parameters["K"]), image_corrected) # # # Equalize and save the images to files image_corrected = equalization_using_histogram(class_image) save_image(IMG_DEST_DIR, "image_isodata8", image_corrected) # image_original = equalization_using_histogram(image) save_image(IMG_DEST_DIR, "image_original", image_original) print "\a\a\a"
from pyradar.core.sar import read_image_from_band from pyradar.core.sar import save_image from pyradar.core.equalizers import equalization_using_histogram IMAGE_PATH = "./img_sar/DAT_01.001" IMG_DEST_DIR = "." # create dataset dataset = create_dataset_from_path(IMAGE_PATH) # get band from dataset band = get_band_from_dataset(dataset) # get geo info from dataset geoinfo = get_geoinfo(dataset, cast_to_int=True) #usually both values are zero xoff = geoinfo['xoff'] yoff = geoinfo['yoff'] # window size in coord x win_xsize = 128 # window size in coord y win_ysize = 128 image = read_image_from_band(band, xoff, yoff, win_xsize, win_ysize) #equalize img to 0:255 image_eq = equalization_using_histogram(image) # save img in current directory save_image(IMG_DEST_DIR, "image_sar", image_eq)
from pyradar.core.sar import save_image from pyradar.core.equalizers import equalization_using_histogram IMAGE_PATH = "./img_sar/DAT_01.001" IMG_DEST_DIR = "." # create dataset dataset = create_dataset_from_path(IMAGE_PATH) # get band from dataset band = get_band_from_dataset(dataset) # get geo info from dataset geoinfo = get_geoinfo(dataset, cast_to_int=True) #usually both values are zero xoff = geoinfo['xoff'] yoff = geoinfo['yoff'] # window size in coord x win_xsize = 128 # window size in coord y win_ysize = 128 image = read_image_from_band(band, xoff, yoff, win_xsize, win_ysize) #equalize img to 0:255 image_eq = equalization_using_histogram(image) # save img in current directory save_image(IMG_DEST_DIR, "image_sar", image_eq)
# pixel x can be stored in (i,j) defined as: # i = x/75 and j = x%75 if pixel < minVal: minVal=pixel Matrix[1][int(x/75)][x%75]=val Matrix[2][int(x/75)][x%75]/=val x+=1 #print(x) ImageArray.append(Matrix) count+=1 print(len(ImageArray)) print(ImageArray[0][0][0][2]) print(minVal) c=1 ''' #img = Image.fromarray(np.uint8(ImageArray[0])) #img.save('myimg.jpeg') image = ImageArray[0][1] # get actual range input_range = image.min(), image.max() # set new range output_range = 0, 255 # equalize image image_eq = naive_equalize_image(image, input_range, output_range) # save image in current directory save_image(".", "image_sar", image_eq) ''' for image in ImageArray: # Creates PIL image