-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add bound constraints in FISTA #2
Open
GaelVaroquaux
wants to merge
8
commits into
emmanuelle:master
Choose a base branch
from
GaelVaroquaux:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e6d3815
COSMIT
GaelVaroquaux d4fa34f
ENH: Add bound constraints in TV
GaelVaroquaux 3f79b11
BUG: Fix tv_denoising fista for 3D
GaelVaroquaux becf215
BUG: fix the constraint TV
GaelVaroquaux b8d1617
BUG: Fix clipping if val_min or val_max is None
AlexandreAbraham 71e9d57
ENH: Prox TV+l1
GaelVaroquaux fa3fd32
Merge pull request #1 from AlexandreAbraham/clip_problem
GaelVaroquaux 6431dae
Small optims in tv_l1 + dual gap
GaelVaroquaux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
""" | ||
Total-variation penalization and bound constraints for tomography reconstruction | ||
================================================================================ | ||
|
||
In this example, we reconstruct an image from its tomography projections | ||
with an uncomplete set of projections (l/8 angles, where l is the linear | ||
size of the image. For a correct reconstruction without a-priori information, | ||
one would usually require l or more angles). In addition, noise is added to | ||
the projections. | ||
|
||
In order to reconstruct the original image, we minimize a function that | ||
is the sum of (i) a L2 data fit term, and (ii) the total variation of the | ||
image, and bound constraints on the pixel values. Proximal iterations | ||
using the FISTA scheme are used. | ||
|
||
We compare with and without the bounds | ||
|
||
This example should take around 1mn to run and plot the results. | ||
""" | ||
|
||
print __doc__ | ||
|
||
import numpy as np | ||
from reconstruction.forward_backward_tv import fista_tv | ||
from reconstruction.projections import build_projection_operator | ||
from reconstruction.util import generate_synthetic_data | ||
from time import time | ||
import matplotlib.pyplot as plt | ||
|
||
# Synthetic data | ||
l = 512 | ||
np.random.seed(0) | ||
x = generate_synthetic_data(l) | ||
|
||
|
||
# Projection operator and projections data, with noise | ||
H = build_projection_operator(l, l / 32) | ||
y = H * x.ravel()[:, np.newaxis] | ||
y += 5 * np.random.randn(*y.shape) | ||
|
||
# Display original data | ||
plt.figure(figsize=(12, 5)) | ||
plt.subplot(2, 3, 1) | ||
plt.imshow(x, cmap=plt.cm.gnuplot2, interpolation='nearest', vmin=-.1, vmax=1.2) | ||
plt.title('original data (256x256)') | ||
plt.axis('off') | ||
|
||
for idx, (val_min, val_max, name) in enumerate([ | ||
(None, None, 'TV'), | ||
(0, 1, 'TV + interval'), | ||
]): | ||
# Reconstruction | ||
t1 = time() | ||
res, energies = fista_tv(y, 50, 100, H, val_min=val_min, | ||
val_max=val_max) | ||
t2 = time() | ||
|
||
# Fraction of errors of segmented image wrt ground truth | ||
err = np.abs(x - (res[-1] > 0.5)).mean() | ||
print "%s: reconstruction done in %f s, %.3f%% segmentation error" % ( | ||
name, t2 - t1, 100 * err) | ||
|
||
plt.subplot(2, 3, 2 + idx) | ||
plt.imshow(res[-1], cmap=plt.cm.gnuplot2, interpolation='nearest', vmin=-.1, | ||
vmax=1.2) | ||
plt.title('reconstruction with %s' % name) | ||
plt.axis('off') | ||
ax = plt.subplot(2, 3, 5 + idx) | ||
ax.yaxis.set_scale('log') | ||
plt.hist(res[-1].ravel(), bins=20, normed=True) | ||
plt.yticks(()) | ||
plt.title('Histogram of pixel intensity') | ||
plt.axis('tight') | ||
|
||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no