{"worksheets": [{"cells": [{"cell_type": "markdown", "metadata": {}, "source": ["Curvelet Denoising", "==================", "", "*Important:* Please read the [installation page](http://gpeyre.github.io/numerical-tours/installation_python/) for details about how to install the toolboxes.", "$\\newcommand{\\dotp}[2]{\\langle #1, #2 \\rangle}$", "$\\newcommand{\\enscond}[2]{\\lbrace #1, #2 \\rbrace}$", "$\\newcommand{\\pd}[2]{ \\frac{ \\partial #1}{\\partial #2} }$", "$\\newcommand{\\umin}[1]{\\underset{#1}{\\min}\\;}$", "$\\newcommand{\\umax}[1]{\\underset{#1}{\\max}\\;}$", "$\\newcommand{\\umin}[1]{\\underset{#1}{\\min}\\;}$", "$\\newcommand{\\uargmin}[1]{\\underset{#1}{argmin}\\;}$", "$\\newcommand{\\norm}[1]{\\|#1\\|}$", "$\\newcommand{\\abs}[1]{\\left|#1\\right|}$", "$\\newcommand{\\choice}[1]{ \\left\\{ \\begin{array}{l} #1 \\end{array} \\right. }$", "$\\newcommand{\\pa}[1]{\\left(#1\\right)}$", "$\\newcommand{\\diag}[1]{{diag}\\left( #1 \\right)}$", "$\\newcommand{\\qandq}{\\quad\\text{and}\\quad}$", "$\\newcommand{\\qwhereq}{\\quad\\text{where}\\quad}$", "$\\newcommand{\\qifq}{ \\quad \\text{if} \\quad }$", "$\\newcommand{\\qarrq}{ \\quad \\Longrightarrow \\quad }$", "$\\newcommand{\\ZZ}{\\mathbb{Z}}$", "$\\newcommand{\\CC}{\\mathbb{C}}$", "$\\newcommand{\\RR}{\\mathbb{R}}$", "$\\newcommand{\\EE}{\\mathbb{E}}$", "$\\newcommand{\\Zz}{\\mathcal{Z}}$", "$\\newcommand{\\Ww}{\\mathcal{W}}$", "$\\newcommand{\\Vv}{\\mathcal{V}}$", "$\\newcommand{\\Nn}{\\mathcal{N}}$", "$\\newcommand{\\NN}{\\mathcal{N}}$", "$\\newcommand{\\Hh}{\\mathcal{H}}$", "$\\newcommand{\\Bb}{\\mathcal{B}}$", "$\\newcommand{\\Ee}{\\mathcal{E}}$", "$\\newcommand{\\Cc}{\\mathcal{C}}$", "$\\newcommand{\\Gg}{\\mathcal{G}}$", "$\\newcommand{\\Ss}{\\mathcal{S}}$", "$\\newcommand{\\Pp}{\\mathcal{P}}$", "$\\newcommand{\\Ff}{\\mathcal{F}}$", "$\\newcommand{\\Xx}{\\mathcal{X}}$", "$\\newcommand{\\Mm}{\\mathcal{M}}$", "$\\newcommand{\\Ii}{\\mathcal{I}}$", "$\\newcommand{\\Dd}{\\mathcal{D}}$", "$\\newcommand{\\Ll}{\\mathcal{L}}$", "$\\newcommand{\\Tt}{\\mathcal{T}}$", "$\\newcommand{\\si}{\\sigma}$", "$\\newcommand{\\al}{\\alpha}$", "$\\newcommand{\\la}{\\lambda}$", "$\\newcommand{\\ga}{\\gamma}$", "$\\newcommand{\\Ga}{\\Gamma}$", "$\\newcommand{\\La}{\\Lambda}$", "$\\newcommand{\\si}{\\sigma}$", "$\\newcommand{\\Si}{\\Sigma}$", "$\\newcommand{\\be}{\\beta}$", "$\\newcommand{\\de}{\\delta}$", "$\\newcommand{\\De}{\\Delta}$", "$\\newcommand{\\phi}{\\varphi}$", "$\\newcommand{\\th}{\\theta}$", "$\\newcommand{\\om}{\\omega}$", "$\\newcommand{\\Om}{\\Omega}$"]}, {"cell_type": "markdown", "metadata": {}, "source": ["This numerical tour explores the use of curvelets to perform image", "denoising."]}, {"cell_type": "code", "language": "python", "metadata": {}, "outputs": [], "collapsed": false, "input": ["from __future__ import division", "import nt_toolbox as nt", "from nt_solutions import denoisingwav_6_curvelets as solutions", "%matplotlib inline", "%load_ext autoreload", "%autoreload 2"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Curvelet Transform", "------------------", "The curvelet tight frame was introduced by Candes and Donoho to enhance the wavelet", "representation of geometric cartoon images. See for instance", "", "", "E.J. Cand s and D. L. Donoho,", "_New tight frames of curvelets and optimal representations of objects with piecewise-C2 singularities_,", "Comm. Pure Appl. Math., 57 219-266", "", "", "In this tour, we use the discrete curvelet transform, detailed in", "", "", "E. J. Cand s, L. Demanet, D. L. Donoho and L. Ying,", "_Fast discrete curvelet transforms_,", "Multiscale Model. Simul., 5 861-899", "", "", "and it uses the implementation.", "", "", "Load an image."]}, {"cell_type": "code", "language": "python", "metadata": {}, "outputs": [], "collapsed": false, "input": ["n = 256", "name = 'lena'", "M = rescale(load_image(name, n))"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Parameters for the curvelet transform."]}, {"cell_type": "code", "language": "python", "metadata": {}, "outputs": [], "collapsed": false, "input": ["options.null = 0", "options.finest = 1", "options.nbscales = 4", "options.nbangles_coarse = 16", "options.is_real = 1", "options.n = n"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Perform the transform."]}, {"cell_type": "code", "language": "python", "metadata": {}, "outputs": [], "collapsed": false, "input": ["MW = perform_curvelet_transform(M, options)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Display the transform."]}, {"cell_type": "code", "language": "python", "metadata": {}, "outputs": [], "collapsed": false, "input": ["plot_curvelet(MW, options)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["One can perform a non-linear approximation of the image by thresholding", "the curvelet coefficients."]}, {"cell_type": "code", "language": "python", "metadata": {}, "outputs": [], "collapsed": false, "input": ["T = .2", "MWT = perform_thresholding(MW, T, 'hard')"]}, {"cell_type": "markdown", "metadata": {}, "source": ["One recovers the approximated image by using the inverse curvelet", "transform."]}, {"cell_type": "code", "language": "python", "metadata": {}, "outputs": [], "collapsed": false, "input": ["M1 = perform_curvelet_transform(MWT, options)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Display the approximation. Note that is not the best non-linear", "approximation since the curvelet tight frame is not an orthogonal basis."]}, {"cell_type": "code", "language": "python", "metadata": {}, "outputs": [], "collapsed": false, "input": ["imageplot(M, 'Original', 1, 2, 1)", "imageplot(clamp(M1), 'Approximated', 1, 2, 2)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Denoising with the Curvelet transform", "-------------------------------------", "Curvelet thresholding is useful to perform denoising.", "", "", "We load a sub-set of the lena image."]}, {"cell_type": "code", "language": "python", "metadata": {}, "outputs": [], "collapsed": false, "input": ["name = 'lena'", "n = 128", "M0 = rescale(crop(load_image(name), n, [108 200]))", "options.n = n"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Add some noise."]}, {"cell_type": "code", "language": "python", "metadata": {}, "outputs": [], "collapsed": false, "input": ["sigma = .05", "M = M0 + sigma*randn(n)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["__Exercise 1__", "", "Compute the best threshold to minimize the denoising error in curvelets.", "Call |Mcurv| the optimal denoising."]}, {"cell_type": "code", "language": "python", "metadata": {}, "outputs": [], "collapsed": false, "input": ["solutions.exo1()"]}, {"cell_type": "code", "language": "python", "metadata": {}, "outputs": [], "collapsed": false, "input": ["## Insert your code here."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Display."]}, {"cell_type": "code", "language": "python", "metadata": {}, "outputs": [], "collapsed": false, "input": ["imageplot(clamp(M), 'Noisy', 1, 2, 1)", "imageplot(clamp(Mcurv), ['Denoised, SNR = ' num2str(snr(M0, Mcurv), 3) 'dB'], 1, 2, 2)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["__Exercise 2__", "", "Perform cycle spinning to enhance the recovery error."]}, {"cell_type": "code", "language": "python", "metadata": {}, "outputs": [], "collapsed": false, "input": ["solutions.exo2()"]}, {"cell_type": "code", "language": "python", "metadata": {}, "outputs": [], "collapsed": false, "input": ["## Insert your code here."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Display."]}, {"cell_type": "code", "language": "python", "metadata": {}, "outputs": [], "collapsed": false, "input": ["imageplot(clamp(M), 'Noisy', 1, 2, 1)", "imageplot(clamp(Mcurv), ['Denoised, SNR = ' num2str(snr(M0, Mcurv), 3)], 1, 2, 2)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["__Exercise 3__", "", "Compare with translation invariant hard thresholding."]}, {"cell_type": "code", "language": "python", "metadata": {}, "outputs": [], "collapsed": false, "input": ["solutions.exo3()"]}, {"cell_type": "code", "language": "python", "metadata": {}, "outputs": [], "collapsed": false, "input": ["## Insert your code here."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Inverse Problem Regularization", "------------------------------", "L1 sparsity in curvelets can be used to regularize inverse problems."]}, {"cell_type": "markdown", "metadata": {}, "source": ["__Exercise 4__", "", "Applies curvelet iterative thresholding to solve an inverse problem such", "as inpainting, deconvolution or compressed sending."]}, {"cell_type": "code", "language": "python", "metadata": {}, "outputs": [], "collapsed": false, "input": ["solutions.exo4()"]}, {"cell_type": "code", "language": "python", "metadata": {}, "outputs": [], "collapsed": false, "input": ["## Insert your code here."]}]}], "nbformat": 3, "metadata": {"name": ""}, "nbformat_minor": 0}