コード例 #1
0
ファイル: test_lulu.py プロジェクト: amared/lulu
    def test_basic(self):
        img = np.random.randint(255, size=(200, 200))

        pulses = lulu.decompose(img)
        img_, areas, area_count = lulu.reconstruct(pulses, img.shape)

        # Write assert this way so that we can see how many
        # pixels mismatch as a percent of the total nr of pixels
        assert_array_equal(img_, img)
        assert_equal(np.sum(img_ != img) / float(np.prod(img.shape)) * 100,
                     0, "Percentage mismatch =")
コード例 #2
0
ファイル: test_lulu.py プロジェクト: lipap/lulu
    def test_basic(self):
        img = np.random.randint(255, size=(200, 200))

        pulses = lulu.decompose(img)
        img_, areas, area_count = lulu.reconstruct(pulses, img.shape)

        # Write assert this way so that we can see how many
        # pixels mismatch as a percent of the total nr of pixels
        assert_array_equal(img_, img)
        assert_equal(
            np.sum(img_ != img) / float(np.prod(img.shape)) * 100, 0,
            "Percentage mismatch =")
コード例 #3
0
ファイル: lulu_filter.py プロジェクト: Magnusvann/WST895
def lulu_filter(noisy,sf):
    prev_smoothed = noisy
    pulses = lulu.decompose(img=noisy,quiet=False,operator='LU')
    smoothness_inc = 0.01
    pulse_len = len(pulses.keys())
    pulses
    i=2
    while 1-smoothness_inc > sf and i < pulse_len:
        lulu_smoothed, areas, area_count = lulu.reconstruct(dict((k, pulses[k]) for k in pulses.keys()[0:i]), noisy.shape)
        lulu_smoothed = noisy - lulu_smoothed
        smoothness_inc = np.var(lulu_smoothed)/np.var(prev_smoothed)
        prev_smoothed = lulu_smoothed
        i = i + 1
    return lulu_smoothed
コード例 #4
0
ファイル: reconstruct.py プロジェクト: amared/lulu
import lulu
import lulu.connected_region_handler as crh

img = load_image()

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

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

print "Execution time: %.2fs" % (toc - tic)

print "-" * 78
print "Reconstructing image...",
out, areas, area_count = lulu.reconstruct(regions, img.shape)
print "done."
print "Reconstructed from %d pulses." % sum(area_count)
print "-" * 78

plt.subplot(2, 2, 1)
plt.imshow(img, interpolation='nearest', cmap=plt.cm.gray)
plt.title('Original')
plt.subplot(2, 2, 2)
plt.imshow(out, interpolation='nearest', cmap=plt.cm.gray)
plt.title('Reconstruction (%d pulses)' % sum(area_count))

plt.subplot(2, 2, 4)
s = np.cumsum(area_count)
midpt = (s[-1] + s[0]) / 2.
ind = np.argmin(np.abs(s - midpt))
コード例 #5
0
ファイル: reconstruct.py プロジェクト: amared/lulu
import lulu
import lulu.connected_region_handler as crh

img = load_image()

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

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

print "Execution time: %.2fs" % (toc - tic)

print "-"*78
print "Reconstructing image...",
out, areas, area_count = lulu.reconstruct(regions, img.shape)
print "done."
print "Reconstructed from %d pulses." % sum(area_count)
print "-"*78

plt.subplot(2, 2, 1)
plt.imshow(img, interpolation='nearest', cmap=plt.cm.gray)
plt.title('Original')
plt.subplot(2, 2, 2)
plt.imshow(out, interpolation='nearest', cmap=plt.cm.gray)
plt.title('Reconstruction (%d pulses)' % sum(area_count))

plt.subplot(2, 2, 4)
s = np.cumsum(area_count)
midpt = (s[-1] + s[0])/2.
ind = np.argmin(np.abs(s - midpt))