Examples

All the examples in one place!

Example of sar_debugger

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pyradar.utils.sar_debugger import take_snapshot

MAX_ITER = 1000

for iter in xrange(0, MAX_ITER):
    image = some_algorithm(image)
    take_snapshot(image, iteration_step=iter)

Example of core2

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# 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(IMG_DEST_DIR, "image_sar", image_eq)

Example of simulate

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pyradar.simulate.image_simulator import ImageSimulator
from pyradar.utils.timeutils import Timer
pylab.close()

timer = Timer()
width, height = 2000, 2000

gamma_ims = ImageSimulator(width, height)
k_ims = ImageSimulator(width, height)
noise_layer_ims = ImageSimulator(width, height)

gamma_params = {'scale': 2.0, 'shape': 3.0}
k_params = {'mean': 2.0, 'shape': 2.0}
noise_layer_params = {'df': 3}

gamma_ims.generate_image_layer(distribution='gamma', params=gamma_params)
k_ims.generate_image_layer(distribution='k', params=k_params)
noise_layer_ims.generate_noise_layer(distribution='chisquare', params=noise_layer_params)

# Make some noise!
gamma_ims.noise_layer = noise_layer_ims.noise_layer
k_ims.noise_layer = noise_layer_ims.noise_layer
gamma_ims.generate_noisy_layer()
k_ims.generate_noisy_layer()

timer.calculate_time_elapsed(print_value=True)
# Export the files:
gamma_ims.export_image_layer(layer_name='image_layer', filename='gamma_img_layer',
                             path_to='.')
k_ims.export_image_layer(layer_name='image_layer', filename='k_img_layer',
                         path_to='.')
gamma_ims.export_image_layer(layer_name='noisy_image', filename='gamma_noisy_img',
                             path_to='.')
k_ims.export_image_layer(layer_name='noisy_image', filename='k_noisy_img',
                         path_to='.')
timer.calculate_time_elapsed(print_value=True)

# Make a plot:
print 'Making a plot to "plot_img.png":'
pylab.close()
gamma_ims.plot_layer_histogram(layer_name='image_layer', filename='plot_gamma_img')
k_ims.plot_layer_histogram(layer_name='image_layer', filename='plot_k_img')

timer.stop_timer()
timer.calculate_time_elapsed(print_value=True)

Example of filtros

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pyradar.filters.frost import frost_filter
from pyradar.filters.kuan import kuan_filter
from pyradar.filters.lee import lee_filter
from pyradar.filters.lee_enhanced import lee_enhanced_filter
from pyradar.filters.median import median_filter
from pyradar.filters.mean import mean_filter

# filters parameters
# window size
winsize = 9
# damping factor for frost
k_value1 = 2.0
# damping factor for lee enhanced
k_value2 = 1.0
# coefficient of variation of noise
cu_value = 0.25
# coefficient of variation for lee enhanced of noise
cu_lee_enhanced = 0.523
# max coefficient of variation for lee enhanced
cmax_value = 1.73

# frost filter
image_frost = frost_filter(image, damping_factor=k_value1, win_size=winsize)
# kuan filter
image_kuan = kuan_filter(image, win_size=winsize, cu=cu_value)
# lee filter
image_lee = lee_filter(image, win_size=winsize, cu=cu_value)
# lee enhanced filter
image_lee_enhanced = lee_enhanced_filter(image, win_size=winsize, k=k_value2,
                                         cu=cu_lee_enhanced, cmax=cmax_value)
# mean filter
image_mean = mean_filter(image, win_size=winsize)
# median filter
image_median = median_filter(image, win_size=winsize)

Example of system_info

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pyradar.utils.system_info import get_system_info
from pyradar.utils.system_info import print_info

info = get_system_info()
print_info(info)

Example of isodata

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# this should be placed at the top with all the imports
from pyradar.classifiers.isodata import isodata_classification

params = {"K": 15, "I" : 100, "P" : 2, "THETA_M" : 10, "THETA_S" : 0.1,
          "THETA_C" : 2, "THETA_O" : 0.01}

# run Isodata
class_image = isodata_classification(img, parameters=params)

# equalize class image to 0:255
class_image_eq = equalization_using_histogram(class_image)
# save it
save_image(IMG_DEST_DIR, "class_image_eq", class_image_eq)
# also save original image
image_eq = equalization_using_histogram(image)
# save it
save_image(IMG_DEST_DIR, "image_eq", image_eq)

Example of core

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pyradar.core.sar import create_dataset_from_path
from pyradar.core.sar import get_band_from_dataset
from pyradar.core.sar import get_geoinfo
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)

Example of kmeans

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# this should be placed at the top with all the imports
from pyradar.classifiers.kmeans import kmeans_classification

# number of clusters
k= 4
# max number of iterations
iter_max = 1000
# run K-Means
class_image = kmeans_classification(image, k, iter_max)

# equalize class image to 0:255
class_image_eq = equalization_using_histogram(class_image)
# save it
save_image(IMG_DEST_DIR, "class_image_eq", class_image_eq)
# also save original image
image_eq = equalization_using_histogram(image)
# save it
save_image(IMG_DEST_DIR, "image_eq", image_eq)

Example of statutils

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np
from pyradar.utils.statutils import compute_cfs
from pyradar.utils.statutils import calculate_pdf_for_pixel
from pyradar.utils.statutils import calculate_cdf_for_pixel
from pyradar.utils.statutils import compute_cdfs
arr = np.array([31, 49, 19, 62, 24, 45, 23, 51, 55, 60, 40, 35,
                54, 26, 57, 37, 43, 65, 18, 41, 50, 56, 4, 54,
                39, 52, 35, 51, 63, 42])
max_value = arr.max()
min_value = arr.min()
start, stop, step = int(min_value), int(max_value + 2), 1

histogram, bin_edge = np.histogram(arr, xrange(start, stop, step))
compute_cfs(histogram)

# >>> array([ 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
#             1,  2,  3,  3, 3,  3,  4,  5,  5,  6,  6,  6,  6,
#             6,  7,  7,  7,  7,  9,  9, 10, 10, 11, 12, 13, 14,
#            15, 15, 16, 16, 16, 16, 17, 18, 20, 21, 21, 23, 24,
#            25, 26, 26, 26, 27, 27, 28, 29, 29, 30])


calculate_pdf_for_pixel(arr, histogram, bin_edge, 54)
# >>> 0.066666666666666666

calculate_pdf_for_pixel(arr, histogram, bin_edge, 20)
# >>> 0.0

calculate_pdf_for_pixel(arr, histogram, bin_edge, 18)
# >>> 0.033333333333333333

calculate_cdf_for_pixel(arr, histogram, bin_edge, 4)
# >>> 0.033333333333333333

calculate_cdf_for_pixel(arr, histogram, bin_edge, 50)
# >>> 0.59999999999999998

compute_cdfs(arr, histogram, bin_edge)

# >>> array([ 0.03333333,  0.03333333,  0.03333333,  0.03333333,  0.03333333,
#             0.03333333,  0.03333333,  0.03333333,  0.03333333,  0.03333333,
#             0.03333333,  0.03333333,  0.03333333,  0.03333333,  0.06666667,
#             0.1       ,  0.1       ,  0.1       ,  0.1       ,  0.13333333,
#             0.16666667,  0.16666667,  0.2       ,  0.2       ,  0.2       ,
#             0.2       ,  0.2       ,  0.23333333,  0.23333333,  0.23333333,
#             0.23333333,  0.3       ,  0.3       ,  0.33333333,  0.33333333,
#             0.36666667,  0.4       ,  0.43333333,  0.46666667,  0.5       ,
#             0.5       ,  0.53333333,  0.53333333,  0.53333333,  0.53333333,
#             0.56666667,  0.6       ,  0.66666667,  0.7       ,  0.7       ,
#             0.76666667,  0.8       ,  0.83333333,  0.86666667,  0.86666667,
#             0.86666667,  0.9       ,  0.9       ,  0.93333333,  0.96666667,
#             0.96666667,  1.        ])

Example of timer

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pyradar.utils.timeutils import Timer

# crea y arranca el timer
simple_timer = Timer()
# procedimiento que queremos medir
result = function(arg1, arg2)
# paramos el timer
simple_timer.stop_timer()
#imprimimos los resultados y los guardamos en diff
diff = simple_timer.calculate_time_elapsed(print_value=True)

Example of comparator

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pyradar.comparator.image_comparator import ImageComparator
from pyradar.examples.sample_matrixes import (numpy_image,
                                              numpy_image1)

im = ImageComparator(numpy_image, numpy_image1)

print 'rmse1: ', im.compare_by('rmse1', None)
print 'rmse2: ', im.compare_by('rmse2', None)
print 'mae: ', im.compare_by('mae', None)
print 'pearson: ', im.compare_by('pearson', None)

isodata working

Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.