Beispiel #1
0
def test_random_sizes():
    # make sure the size is not a problem

    niter = 10
    elem = np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]], dtype=np.uint8)
    for m, n in np.random.random_integers(1, 100, size=(10, 2)):
        mask = np.ones((m, n), dtype=np.uint8)

        image8 = np.ones((m, n), dtype=np.uint8)
        out8 = np.empty_like(image8)
        rank.mean(image=image8,
                  selem=elem,
                  mask=mask,
                  out=out8,
                  shift_x=0,
                  shift_y=0)
        assert_array_equal(image8.shape, out8.shape)
        rank.mean(image=image8,
                  selem=elem,
                  mask=mask,
                  out=out8,
                  shift_x=+1,
                  shift_y=+1)
        assert_array_equal(image8.shape, out8.shape)

        image16 = np.ones((m, n), dtype=np.uint16)
        out16 = np.empty_like(image8, dtype=np.uint16)
        rank.mean(image=image16,
                  selem=elem,
                  mask=mask,
                  out=out16,
                  shift_x=0,
                  shift_y=0)
        assert_array_equal(image16.shape, out16.shape)
        rank.mean(image=image16,
                  selem=elem,
                  mask=mask,
                  out=out16,
                  shift_x=+1,
                  shift_y=+1)
        assert_array_equal(image16.shape, out16.shape)

        rank.mean_percentile(image=image16,
                             mask=mask,
                             out=out16,
                             selem=elem,
                             shift_x=0,
                             shift_y=0,
                             p0=.1,
                             p1=.9)
        assert_array_equal(image16.shape, out16.shape)
        rank.mean_percentile(image=image16,
                             mask=mask,
                             out=out16,
                             selem=elem,
                             shift_x=+1,
                             shift_y=+1,
                             p0=.1,
                             p1=.9)
        assert_array_equal(image16.shape, out16.shape)
Beispiel #2
0
def test_selem_dtypes():

    image = np.zeros((5, 5), dtype=np.uint8)
    out = np.zeros_like(image)
    mask = np.ones_like(image, dtype=np.uint8)
    image[2, 2] = 255
    image[2, 3] = 128
    image[1, 2] = 16

    for dtype in (np.uint8, np.uint16, np.int32, np.int64, np.float32,
                  np.float64):
        elem = np.array([[0, 0, 0], [0, 1, 0], [0, 0, 0]], dtype=dtype)
        rank.mean(image=image,
                  selem=elem,
                  out=out,
                  mask=mask,
                  shift_x=0,
                  shift_y=0)
        assert_array_equal(image, out)
        rank.mean_percentile(image=image,
                             selem=elem,
                             out=out,
                             mask=mask,
                             shift_x=0,
                             shift_y=0)
        assert_array_equal(image, out)
Beispiel #3
0
def test_random_sizes():
    # make sure the size is not a problem

    niter = 10
    elem = np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]], dtype=np.uint8)
    for m, n in np.random.random_integers(1, 100, size=(10, 2)):
        mask = np.ones((m, n), dtype=np.uint8)

        image8 = np.ones((m, n), dtype=np.uint8)
        out8 = np.empty_like(image8)
        rank.mean(image=image8, selem=elem, mask=mask, out=out8,
                  shift_x=0, shift_y=0)
        assert_array_equal(image8.shape, out8.shape)
        rank.mean(image=image8, selem=elem, mask=mask, out=out8,
                  shift_x=+1, shift_y=+1)
        assert_array_equal(image8.shape, out8.shape)

        image16 = np.ones((m, n), dtype=np.uint16)
        out16 = np.empty_like(image8, dtype=np.uint16)
        rank.mean(image=image16, selem=elem, mask=mask, out=out16,
                  shift_x=0, shift_y=0)
        assert_array_equal(image16.shape, out16.shape)
        rank.mean(image=image16, selem=elem, mask=mask, out=out16,
                  shift_x=+1, shift_y=+1)
        assert_array_equal(image16.shape, out16.shape)

        rank.mean_percentile(image=image16, mask=mask, out=out16,
                             selem=elem, shift_x=0, shift_y=0, p0=.1, p1=.9)
        assert_array_equal(image16.shape, out16.shape)
        rank.mean_percentile(image=image16, mask=mask, out=out16,
                             selem=elem, shift_x=+1, shift_y=+1, p0=.1, p1=.9)
        assert_array_equal(image16.shape, out16.shape)
Beispiel #4
0
def test_selem_dtypes():

    image = np.zeros((5, 5), dtype=np.uint8)
    out = np.zeros_like(image)
    mask = np.ones_like(image, dtype=np.uint8)
    image[2, 2] = 255
    image[2, 3] = 128
    image[1, 2] = 16

    for dtype in (np.uint8, np.uint16, np.int32, np.int64,
                  np.float32, np.float64):
        elem = np.array([[0, 0, 0], [0, 1, 0], [0, 0, 0]], dtype=dtype)
        rank.mean(image=image, selem=elem, out=out, mask=mask,
                  shift_x=0, shift_y=0)
        assert_array_equal(image, out)
        rank.mean_percentile(image=image, selem=elem, out=out, mask=mask,
                             shift_x=0, shift_y=0)
        assert_array_equal(image, out)
Beispiel #5
0
def test_bitdepth():
    # test the different bit depth for rank16

    elem = np.ones((3, 3), dtype=np.uint8)
    out = np.empty((100, 100), dtype=np.uint16)
    mask = np.ones((100, 100), dtype=np.uint8)

    for i in range(5):
        image = np.ones((100, 100), dtype=np.uint16) * 255 * 2 ** i
        r = rank.mean_percentile(image=image, selem=elem, mask=mask,
                                 out=out, shift_x=0, shift_y=0, p0=.1, p1=.9)
Beispiel #6
0
def test_bitdepth():
    # test the different bit depth for rank16

    elem = np.ones((3, 3), dtype=np.uint8)
    out = np.empty((100, 100), dtype=np.uint16)
    mask = np.ones((100, 100), dtype=np.uint8)

    for i in range(5):
        image = np.ones((100, 100), dtype=np.uint16) * 255 * 2 ** i
        r = rank.mean_percentile(image=image, selem=elem, mask=mask,
                                 out=out, shift_x=0, shift_y=0, p0=.1, p1=.9)
Beispiel #7
0
def main(arguments):
    #Read input GeoTIFF file
    in_data = GeoRead(arguments['IN_FILE'])

    #--------------------------------------------------------------#
    # Alogirtihm
    # Read image -> Scale down to [-1,1] -> Mean_percentile -> 
    #Erosion -> Scale up new image upto original maxima and minima
    #--------------------------------------------------------------#

    # Consider the sun spikes as noise
    print "Reading input GeoTIFF file..."
    noisy_image = in_data.arys[0]
    print "The maxima is %f & the minima is %f.\n" %(np.max(noisy_image), np.min(noisy_image))

    # Scale array data to [-1,1] so that mean_percentile can implemented
    print "Scaling input data to [-1,1]..."
    noisy_image_scaled = scale_down(noisy_image, 1.0, -1.0)
    print "Done construction of scaled noisy_image.\n"

    #Disk size for implementing mean percentile
    #selem = disk(5) #Not good
    #selem = disk(10) #Can be better
    selem = disk(15)
    #selem = disk(20) #Not good

    #Applying mean percentile
    print "Applying Mean percentile with p0 = 0.1 & p1 = 0.9..."
    percentile_result = rank.mean_percentile(noisy_image_scaled, selem=selem, p0=.1, p1=.9)
    print "Done construction of percentile_result.\n"

    #Applying erosion. 
    print "Applying erosion to remove the sun spikes..."
    sun_spikes_removed = erosion(percentile_result, selem)
    print "Done construction of sun spikes removed scaled down result.\n"

    #Scaling the final result to original scale
    print "Scaling the final output to maxima and minima of original image..."
    sun_spikes_removed_original_scale = scale_up(noisy_image, sun_spikes_removed)
    print "Process completed.\n"


    # Writing Output
    Screen_out = False
    print "Screen_output is %r." %(Screen_out)
    write_output(Screen_out, noisy_image, noisy_image_scaled, percentile_result, sun_spikes_removed, sun_spikes_removed_original_scale)

    #Plot data
    print "Generating plots..."
    plot_output(noisy_image, percentile_result, sun_spikes_removed, sun_spikes_removed_original_scale)

    print "Script completed successfully."
Beispiel #8
0
complete image (background and details). Bilateral mean exhibits a high
filtering rate for continuous area (i.e. background) while higher image
frequencies remain untouched.

"""
import numpy as np
import matplotlib.pyplot as plt

from skimage import data
from skimage.morphology import disk
from skimage.filter import rank

image = (data.coins()).astype(np.uint16) * 16
selem = disk(20)

percentile_result = rank.mean_percentile(image, selem=selem, p0=.1, p1=.9)
bilateral_result = rank.mean_bilateral(image, selem=selem, s0=500, s1=500)
normal_result = rank.mean(image, selem=selem)

fig, axes = plt.subplots(nrows=3, figsize=(8, 10))
ax0, ax1, ax2 = axes

ax0.imshow(np.hstack((image, percentile_result)))
ax0.set_title('Percentile mean')
ax0.axis('off')

ax1.imshow(np.hstack((image, bilateral_result)))
ax1.set_title('Bilateral mean')
ax1.axis('off')

ax2.imshow(np.hstack((image, normal_result)))
Beispiel #9
0
filtering rate for continuous area (i.e. background) while higher image
frequencies remain untouched.

"""
import numpy as np
import matplotlib.pyplot as plt

from skimage import data
from skimage.morphology import disk
from skimage.filter import rank


image = (data.coins()).astype(np.uint16) * 16
selem = disk(20)

percentile_result = rank.mean_percentile(image, selem=selem, p0=.1, p1=.9)
bilateral_result = rank.mean_bilateral(image, selem=selem, s0=500, s1=500)
normal_result = rank.mean(image, selem=selem)


fig, axes = plt.subplots(nrows=3, figsize=(8, 10))
ax0, ax1, ax2 = axes

ax0.imshow(np.hstack((image, percentile_result)))
ax0.set_title('Percentile mean')
ax0.axis('off')

ax1.imshow(np.hstack((image, bilateral_result)))
ax1.set_title('Bilateral mean')
ax1.axis('off')