Example #1
0
    show_image(class_image_eq, 'isodata_classification')


SAMPLES = [
    ('equalization_using_histogram', eq),
    ('naive_equalize_image', naive_eq),
    ('filters_eq', filters_eq),
    ('isodata', iso),
    ('kmeans', kmeans),
]

if __name__ == '__main__':
    IMAGE_PATH = "./img_sar/DAT_01.001"
    IMG_DEST_DIR = "."
    dataset = create_dataset_from_path(IMAGE_PATH)
    band = get_band_from_dataset(dataset)
    geoinfo = get_geoinfo(dataset, cast_to_int=True)
    xoff = geoinfo['xoff']
    yoff = geoinfo['yoff']
    win_xsize = 256
    win_ysize = 256
    image = read_image_from_band(band, xoff, yoff, win_xsize, win_ysize)
    keys = SAMPLES
    i = np.array(image).astype('float64')
    filters_eq(i)
    while (True):
        print('\n'.join(['%s). %s' % (id, k[0]) for id, k in enumerate(keys)]))
        print('-------------- \n')
        q = input('Select demo ID: ')
        keys[int(q)][1](image)
Example #2
0
    show_image(class_image_eq, 'isodata_classification')


SAMPLES = [
    ('equalization_using_histogram', eq),
    ('naive_equalize_image', naive_eq),
    ('filters_eq', filters_eq),
    ('isodata', iso),
    ('kmeans', kmeans),
]

if __name__ == '__main__':
    IMAGE_PATH = "./img_sar/DAT_01.001"
    IMG_DEST_DIR = "."
    dataset = create_dataset_from_path(IMAGE_PATH)
    band = get_band_from_dataset(dataset)
    geoinfo = get_geoinfo(dataset, cast_to_int=True)
    xoff = geoinfo['xoff']
    yoff = geoinfo['yoff']
    win_xsize = 256
    win_ysize = 256
    image = read_image_from_band(band, xoff, yoff, win_xsize, win_ysize)
    keys = SAMPLES
    i = np.array(image).astype('float64')
    filters_eq(i)
    while (True):
        print('\n'.join(['%s). %s' % (id, k[0]) for id, k in enumerate(keys)]))
        print('-------------- \n')
        q = input('Select demo ID: ')
        keys[int(q)][1](image)
Example #3
0
    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"
Example #4
0
    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"