Introduction

This python package provides methods and utilities to explore the PnP algorithm and MACE framework in the context of image reconstruction problems, along with some simple demos. The ideas leading to this package are outlined in

with more detail in the papers in the references.

Documentation on this package is available at https://pnp-mace.readthedocs.io, which includes installation instructions.

Demo files are available as python scripts and Jupyter notebooks. See the Demos page for more details.

Indices and tables

Introduction

This python package provides methods and utilities to explore the PnP algorithm and MACE framework in the context of image reconstruction problems, along with some simple demos. The ideas leading to this package are outlined in

with more detail in the papers in the references.

Documentation on this package is available at https://pnp-mace.readthedocs.io, which includes installation instructions.

Demo files are available as python scripts and Jupyter notebooks. See the Demos page for more details.

Installation

Stable release

The pnp_mace package requires python 3.6 or higher, and it’s recommended that you install in a virtual environment. If those conditions are satisfied, you can install pnp_mace by running this command in your activated virtual environment in your terminal:

pip install pnp_mace

Then move on to Running the Demos

Detailed installation instructions

If you don’t know which version of python you have or whether you have a virtual environment or if you have pip, you can follow these instructions:

  1. Create a directory, say pnp_mace_code and change into this directory (or change to the PnP-MACE/demo directory if you’ve downloaded from github).

  2. In a terminal, enter python --version. If this returns 2.X.Y, then use

python3 -m venv new_venv
source new_venv/bin/activate

Otherwise use

python -m venv new_venv
source new_venv/bin/activate

After this step, python will be mapped to a version of python and supporting code that are appropriate for the pnp_mace package. Even if your original python mapped to version 2, now when you enter python --version you should get 3.X.Y.

  1. In the same terminal window, enter pip install pnp_mace

Now the pnp_mace package is available in python using import pnp_mace or import pnp_mace as pnpm

When you are finished using pnp_mace, enter deactivate to exit this virtual environment.

The next time you want to use pnp_mace, change to the directory you created above and enter source new_venv/bin/activate. You do not need to use pip a second time.

Running the demos
  1. Follow the installation instructions above and activate the virtual environment.

  2. If you already have the PnP-MACE/demo directory from https://github.com/gbuzzard/PnP-MACE then change into that directory (you can get this by downloading the tarball and uncompress). Otherwise change into the directory you created during installation and download all the files at https://github.com/gbuzzard/PnP-MACE/tree/master/demo.

  3. In your terminal window, enter pip install -r requirements_demo.txt

  4. In your terminal window, enter python ct.py. You should get some text output regarding the operation of the demo, followed shortly by some images demonstrating the reconstruction. Repeat for the remaining demos.

From sources

The sources for PnP-MACE can be downloaded from the Github repo.

You can either clone the public repository:

$ git clone https://github.com/gbuzzard/PnP-MACE

(see https://git-scm.com/downloads to install git) or download the tarball:

$ curl -OJL https://github.com/gbuzzard/PnP-MACE/tarball/master

Once you have a copy of the source, you can install it with:

$ python setup.py install

Usage

To use PnP-MACE in a project:

import pnp_mace

or:

import pnp_mace as pnpm

Read about the demos to learn more.

Demos

The demos folder in the github repo (https://github.com/gbuzzard/PnP-MACE) includes simple demos illustrating an elementary approach to superresolution and a CT example with high-dynamic-range images.

These demos are not meant to be state-of-the-art either in terms of reconstruction quality or run-time performance. Rather, they are meant to be an invitation to explore these algorithms, to try alternative priors, to understand the effect of parameters on the reconstruction, and to adapt the code to other applications.

The demo folder under https://github.com/gbuzzard/PnP-MACE includes both .py files to be run with python and Jupyter notebooks that can be opened in Google colaboratory for experimentation online.

See the instructions under Running the demos in the Installation instructions to run the demos.

Select the demo names below to see more detailed descriptions.

demo.ct_mace

This demo illustrates a 2D tomography example using a high-dynamic range phantom.

demo.superres_mace

This demo illustrates the solution of a MACE problem using Mann iteration and the stacked operators F and G.

demo.superres_pnp

Overview: A simple demo to demonstrate the solution of a PnP problem The forward model is a subsampling operation, and the prior agent is the bm3d denoiser.

demo

API Documentation

All of the classes and methods are available from the top level import of pnp_mace. That is, if you include import pnp_mace as pnpm in a file, then you can use pnpm to access the methods in pnp_mace.utils (for instance pnp_mace.utils.load_img can be accessed as pnpm.load_img.) Likewise for the methods and classes in other submodules.

pnp_mace.pnpadmm

Plug and Play ADMM alorithm.

pnp_mace.equilibriumproblem

EquilibriumProblem class and solution methods.

pnp_mace.agent

Generic agent.

pnp_mace.forwardagent

Forward agents.

pnp_mace.prioragent

Prior agents.

pnp_mace.utils

Utility functions.

pnp_mace

References

1

Gregery T. Buzzard, Stanley H. Chan, Suhas Sreehari, and Charles A. Bouman. Plug-and-play unplugged: optimization-free reconstruction using consensus equilibrium. SIAM Journal on Imaging Sciences, 11(3):2001–2020, 2018. doi:10.1137/17M1122451.

2

Venkatesh Sridhar, Xiao Wang, Gregery T. Buzzard, and Charles A. Bouman. Distributed iterative CT reconstruction using multi-agent consensus equilibrium. IEEE Transactions on Computational Imaging, 6:1153–1166, 2020. doi:10.1109/tci.2020.3008782.

Contributing

Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.

You can contribute in many ways:

Types of Contributions

Report Bugs

Report bugs at https://github.com/gbuzzard/PnP-MACE/issues.

If you are reporting a bug, please include:

  • Your operating system name and version.

  • Any details about your local setup that might be helpful in troubleshooting.

  • Detailed steps to reproduce the bug.

Fix Bugs

Look through the GitHub issues for bugs. Anything tagged with “bug” and “help wanted” is open to whoever wants to implement it.

Implement Features

Look through the GitHub issues for features. Anything tagged with “enhancement” and “help wanted” is open to whoever wants to implement it.

Write Documentation

PnP-MACE could always use more documentation, whether as part of the official PnP-MACE docs, in docstrings, or even on the web in blog posts, articles, and such.

Submit Feedback

The best way to send feedback is to file an issue at https://github.com/gbuzzard/PnP-MACE/issues.

If you are proposing a feature:

  • Explain in detail how it would work.

  • Keep the scope as narrow as possible, to make it easier to implement.

  • Remember that this is a volunteer-driven project, and that contributions are welcome :)

Get Started!

Ready to contribute? Here’s how to set up pnp_mace for local development.

  1. Fork the pnp_mace repo on GitHub.

  2. Clone your fork locally:

    $ git clone git@github.com:your_name_here/pnp_mace.git
    
  3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:

    $ mkvirtualenv pnp_mace
    $ cd pnp_mace/
    $ python setup.py develop
    
  4. Create a branch for local development:

    $ git checkout -b name-of-your-bugfix-or-feature
    

    Now you can make your changes locally.

  5. When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:

    $ flake8 pnp_mace tests
    $ python setup.py test or pytest
    $ tox
    

    To get flake8 and tox, just pip install them into your virtualenv.

  6. Commit your changes and push your branch to GitHub:

    $ git add .
    $ git commit -m "Your detailed description of your changes."
    $ git push origin name-of-your-bugfix-or-feature
    
  7. Submit a pull request through the GitHub website.

Pull Request Guidelines

Before you submit a pull request, check that it meets these guidelines:

  1. The pull request should include tests.

  2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.

  3. The pull request should work for Python 3.5, 3.6, 3.7 and 3.8, and for PyPy. Check https://travis-ci.com/gbuzzard/PnP-MACE/pull_requests and make sure that the tests pass for all supported Python versions.

Tips

To run a subset of tests:

$ python -m unittest tests.test_pnp_mace

Deploying

A reminder for the maintainers on how to deploy. Make sure all your changes are committed (including an entry in HISTORY.rst). Then run:

$ bump2version patch # possible: major / minor / patch
$ git push
$ git push --tags

Travis will then deploy to PyPI if tests pass.

Credits

Development Lead

Contributors

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.