示例#1
0
            bracket(t)
            for t in ('amplitude_threshold', 'area_threshold',
                      'volume_threshold', 'circularity', 'lifetime'))

        for tname in ('absolute_sum', 'amplitudes_one', 'replace', 'subtract',
                      'output_threshold', 'pulses_used'):
            out += ('\n%s: %s' % (pptrait(tname), getattr(self, tname)))

        return out


if __name__ == "__main__":
    import sys
    if len(sys.argv) >= 2 and '-UL' in sys.argv:
        operator = 'UL'
        sys.argv.remove('-UL')
    else:
        operator = 'LU'

    image = load_image()

    print("Decomposing using the %s operator." % operator)
    if operator == 'LU':
        print("Use the '-UL' flag to switch to UL.")

    print()
    pulses = lulu.decompose(image, operator=operator)

    viewer = Viewer(pulses=pulses, image=image)
    viewer.configure_traits()
示例#2
0
文件: pulses_3D.py 项目: amared/lulu
import sys
sys.path.insert(0, '..')

from enthought.mayavi import mlab
import numpy as np

from demo import load_image

import lulu
import lulu.connected_region_handler as crh

img = load_image('chelsea_small.jpg')

print "Decomposing a %s image." % str(img.shape)
regions = lulu.decompose(img)

value_maxes = []
height = 0
for area in sorted(regions.keys()):
    pulses = regions[area]

    if len(pulses) == 0 or area < 280 or area > 300:
        continue

    values = [crh.get_value(p) for p in pulses]
    height_diff = max(values) - min(values)
    value_maxes.append(height_diff)
    centre = height + height_diff / 2.0

    pulse_values = np.zeros_like(img)
    for p in pulses:
示例#3
0
import sys
sys.path.insert(0, '..')

from demo import load_image

import time
import lulu

img = load_image()

print "Decomposing a %s matrix." % str(img.shape)

tic = time.time()
regions = lulu.decompose(img)
toc = time.time()

print "Execution time: %.2fs" % (toc - tic)
示例#4
0
文件: segment.py 项目: stefanv/lulu
# ----- Segmentation parameters -----
N = 4
beta = 1.5 # Smoothing
min_area = 500
# -----------------------------------

from demo import load_image

import numpy as np
from scipy.cluster.vq import kmeans2
import matplotlib.pyplot as plt

import lulu
import lulu.connected_region_handler as crh

img = load_image('truck_and_apcs_small.jpg')

pulses = lulu.decompose(img)

impulse_strength = np.zeros(img.shape, dtype=int)
for area in pulses:
    if area > min_area:
        for cr in pulses[area]:
            crh.set_array(impulse_strength, cr,
                          np.abs(crh.get_value(cr)), 'add')

def ICM(data, N, beta):
    print("Performing ICM segmentation...")

    # Initialise segmentation using kmeans
    print("K-means initialisation...")
示例#5
0
文件: segment.py 项目: lipap/lulu
# ----- Segmentation parameters -----
N = 4
beta = 1.5  # Smoothing
min_area = 500
# -----------------------------------

from demo import load_image

import numpy as np
from scipy.cluster.vq import kmeans2
import matplotlib.pyplot as plt

import lulu
import lulu.connected_region_handler as crh

img = load_image('truck_and_apcs_small.jpg')

pulses = lulu.decompose(img)

impulse_strength = np.zeros(img.shape, dtype=int)
for area in pulses:
    if area > min_area:
        for cr in pulses[area]:
            crh.set_array(impulse_strength, cr, np.abs(crh.get_value(cr)),
                          'add')


def ICM(data, N, beta):
    print("Performing ICM segmentation...")

    # Initialise segmentation using kmeans
示例#6
0
文件: viewer.py 项目: stefanv/lulu
        out = '\n'.join(bracket(t) for t in
                        ('amplitude_threshold', 'area_threshold',
                         'volume_threshold', 'circularity', 'lifetime'))

        for tname in ('absolute_sum', 'amplitudes_one', 'replace', 'subtract',
                      'output_threshold', 'pulses_used'):
            out += ('\n%s: %s' % (pptrait(tname), getattr(self, tname)))

        return out


if __name__ == "__main__":
    import sys
    if len(sys.argv) >= 2 and '-UL' in sys.argv:
        operator = 'UL'
        sys.argv.remove('-UL')
    else:
        operator = 'LU'

    image = load_image()

    print("Decomposing using the %s operator." % operator)
    if operator == 'LU':
        print("Use the '-UL' flag to switch to UL.")

    print()
    pulses = lulu.decompose(image, operator=operator)

    viewer = Viewer(pulses=pulses, image=image)
    viewer.configure_traits()
示例#7
0
文件: volume.py 项目: stefanv/lulu
from demo import load_image

import matplotlib.pyplot as plt

import numpy as np

import lulu
import lulu.connected_region_handler as crh

img = load_image("truck_and_apcs_small.jpg")

pulses = lulu.decompose(img)

areas = sorted(pulses.keys())
cumulative_volume = []
volumes = []
reconstruction = np.zeros_like(img)
for area in areas:
    area_volume = 0
    for cr in pulses[area]:
        area_volume += crh.nnz(cr) * abs(crh.get_value(cr))
        crh.set_array(reconstruction, cr, abs(crh.get_value(cr)), "add")
    cumulative_volume.append(np.sum(reconstruction))
    volumes.append(area_volume)

total_volume = np.sum(reconstruction)
cumulative_volume = np.array(cumulative_volume)
cumulative_volume = 1 - cumulative_volume / float(total_volume)

plt.subplot(1, 3, 1)
plt.imshow(img, interpolation="nearest", cmap=plt.cm.gray)
示例#8
0
文件: pulses_3D.py 项目: amared/lulu
import sys
sys.path.insert(0, '..')

from enthought.mayavi import mlab
import numpy as np

from demo import load_image

import lulu
import lulu.connected_region_handler as crh

img = load_image('chelsea_small.jpg')

print "Decomposing a %s image." % str(img.shape)
regions = lulu.decompose(img)

value_maxes = []
height = 0
for area in sorted(regions.keys()):
    pulses = regions[area]

    if len(pulses) == 0 or area < 280 or area > 300:
        continue

    values = [crh.get_value(p) for p in pulses]
    height_diff = max(values) - min(values)
    value_maxes.append(height_diff)
    centre = height + height_diff / 2.0

    pulse_values = np.zeros_like(img)
    for p in pulses: