Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ var/
.installed.cfg
*.egg

# pytest cache
.pytest_cache

# package and build testing
build
dist
*.egg-info


## development tools
# pycharm
.idea
# visual studio code
.vscode

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
Expand Down
41 changes: 17 additions & 24 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
Copyright (c) 2018, University of California and The National Institues of Health. All rights reserved.
Copyright (c) 2018, University of California and The National Institutes of Health.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* The name of the University of California may not be used to
endorse or promote products derived from this software without
specific prior written permission.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS
IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

For portions of this code, copyright and license information differs from
the above. In these cases, copyright and/or license information is inline.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
91 changes: 49 additions & 42 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
BIFS Module Repository
========================
======================

This project is an implementation of Bayesian imaging in Fourier Space
(BIFS). For details on the method see, e.g.:

J. Kornak, K. Young, N. Schuff, A. Du, A. A. Maudsley, M. W. Weiner.
- J. Kornak, K. Young, N. Schuff, A. Du, A. A. Maudsley, M. W. Weiner.
K-Bayes Reconstruction for Perfusion MRI I: Concepts and Application. Journal of Digital Imaging. (2009) Feb 10
J. Kornak, K. Young.
- J. Kornak, K. Young.
K-Bayes Reconstruction for Perfusion MRI II: Modeling Motivation
and Technical Development. Journal of Digital Imaging. (2009) Mar 10
J. Kornak , K. Young, B.J. Soher, A.A. Maudsley.
- J. Kornak , K. Young, B.J. Soher, A.A. Maudsley.
Bayesian k -space-time reconstruction of MR spectroscopic imaging for enhanced resolution. IEEE Trans Med Imaging. 2010 Jul;29(7):1333-50.

The basic idea is to perform something like a Bayesian image
Expand All @@ -19,6 +19,7 @@ efficient way by transforming to a space in which the degrees of
freedom can, at least approximately, be treated independently.
For a large class of images, transforming to a Fourier space
representation appears to accomplish this quite well.

And to emphasize a point that sometimes arises as a point of
confusion regarding this method, the goal is NOT to find a transform
that results in a parsimonious representation of the image, but one
Expand All @@ -41,14 +42,18 @@ Python, e.g. Enthought's Canopy environment).
The currently required packages are (BIFS is known to work with
the following versions but will typically work with many earlier
versions as well):
Python 3
numpy 1.15.4-2
scipy 1.2.1-1
matplotlib 2.2.4-2
imageio 2.4.1
jsonpickle 1.2
pyqt5 5.7.1-1 (note: some version of PyQT 5 is required, i.e.
(the package will not work with PyQT 4)

::

Python 3
numpy 1.15.4-2
scipy 1.2.1-1
matplotlib 2.2.4-2
imageio 2.4.1
jsonpickle 1.2
pyqt5 5.7.1-1
(note: some version of PyQT 5 is required, i.e.
the package will not work with PyQT 4)


Using the Package
Expand All @@ -70,10 +75,10 @@ py -3 bifs_gui.py
This provides the easiest access to the BIFS package but provides
limited access to BIFS class variables.

To gain full access to the capabilities of BIFS one can: 1) run python,
2) load the BIFS class (import bifs), and 3) e.g. modify the
commands in one of the scripts (e.g. bifs_cl_2D.py) described below
to suit one's particular project.
To gain full access to the capabilities of BIFS one can:
1) run python
2) load the BIFS class (import bifs)
3) e.g. modify the commands in one of the scripts (e.g. bifs_cl_2D.py) described below to suit one's particular project.

Empirical Priors
~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -148,6 +153,8 @@ provided with the package (and mentioned above).

Class variables available to constructor:

::

init_image - initial loaded image
k_image - initial k-space image
mod_image - initial modulus image in k-space
Expand All @@ -161,27 +168,30 @@ Class variables available to constructor:

image_file_loaded - whether an image is loaded (True,False)
initial_image_file_name - file name of initial image

imdim - int image dimension (1,2 or 3)
imdim1 - int specifying size of 1st dimension of image
imdim2 - int specifying size of 2nd dimension of image
imdim3 - int specifying size of possible 3rd dimension of "image"

kdist = distance function on the shifted k-space lattice

view3Dslice - for 3D data this is a 2D array [a,b] where:
a = axis perpendicular to slice
b = fraction of maximum along that direction
for slice location
view3Dslice - for 3D data this is a 2D array [a,b] where::
a = axis perpendicular to slice
b = fraction of maximum along that direction
for slice location

prior - string specifying the prior distribution function to use
current choices are:
'Gaussian'
'Gaussian'

prior_choices - list of current prior distribution
function choices (see above)
prior_mean_init - prior mean before parameter space function
is set up (used for tests)
prior_mean - the prior mean defined at each k-space point
prior_mean - the prior mean defined at each k-space point
by the k-space parameter function

prior_std - the prior std defined at each k-space point
prior_scale - the overall scale of the prior variance
prior_scale_orig - prior scale at the origin - generally set huge
Expand All @@ -197,15 +207,13 @@ Class variables available to constructor:

bessel_approx_lims - limits for bessel approximation for rice
distribution - see paper referenced in code

bessel_approx_array - array for bessel approximation for rice
distribution - see paper referenced in code

rice_denom_cutoff - cutoff for the denominator of the closed form
of the posterior with a Gaussian prior and
Rician likelihood derived from bessel approximation
see paper referenced in code

param_func_type - string specifying the k-space BIFS parameter
function to use
current choices are:
Expand All @@ -218,30 +226,28 @@ Class variables available to constructor:
decay - float decay exponent for the inverse power parameter function
bvec - 2D float array specifying intercept and amplitude for parameter
space functions
banded_cutoff - cutoff for banded, inverse power k-space parameter function

banded_cutoff - cutoff for banded, inverse power k-space parameter function
basis - string specifying the basis to use - currently only choice
is "Fourier"

basis_choices - list of current choices (see above)

bumps - dictionary containing set of "bump filters" to implement
note: these "bump filters" are elements that are added
to the parameter function to increase (or decrease if the
amplitude is specified as negative) the sensitivity of the
analysis to frequency ranges known in advance to be important
(or missing) in the analyzed images. E.g. if there is a
predominance of features of a give size, adding filters at
wavelengths corresponding to that size could enhance the
sensitivity of the analysis. The scipy.signal package
provides a number of filters meant to applied in
the time (image) domain to characterize properties in the
Fourier domain. Providing these shapes for application in
the Fourier domain for BIFS was straightforward and might
be interesting to experiment with re. effective image
feature enhancement.


to the parameter function to increase (or decrease if the
amplitude is specified as negative) the sensitivity of the
analysis to frequency ranges known in advance to be important
(or missing) in the analyzed images. E.g. if there is a
predominance of features of a give size, adding filters at
wavelengths corresponding to that size could enhance the
sensitivity of the analysis. The scipy.signal package
provides a number of filters meant to applied in
the time (image) domain to characterize properties in the
Fourier domain. Providing these shapes for application in
the Fourier domain for BIFS was straightforward and might
be interesting to experiment with re. effective image
feature enhancement.

bump_types - set of choices for "bump" filter types to add to k-space
parameter function; uses scipy.signal window types
so consult that documentation for available types -
Expand All @@ -257,6 +263,7 @@ Class variables available to constructor:
"blackmanharris"
"nuttall"
"barthann"

bump_default_type - the default window type used (currently "blackman")


1 change: 0 additions & 1 deletion bifs/__init__.py

This file was deleted.

13 changes: 13 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[metadata]
# This includes the license file(s) in the wheel.
# https://wheel.readthedocs.io/en/stable/user_guide.html#including-license-files-in-the-generated-wheel-file
license_files = 'LICENSE'

[bdist_wheel]
# This flag says to generate wheels that support both Python 2 and Python
# 3. If your code will not run unchanged on both Python 2 and 3, you will
# need to generate separate wheels for each Python version that you
# support. Removing this line (or setting universal to 0) will prevent
# bdist_wheel from trying to make a universal wheel. For more see:
# https://packaging.python.org/guides/distributing-packages-using-setuptools/#wheels
universal=1
51 changes: 45 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,61 @@
with open('LICENSE') as f:
license = f.read()

packages_ = find_packages('src')

setup(
name='bifs',
version='0.2.0',
version='0.1.0a5',
description='Implementation of Bayesian Imaging in Fourier Space (BIFS)',
long_description=readme,
author='John Kornak, Karl Young, Ross Boylan',
author_email='john.kornak@ucsf.edu,kyoung21b2000@gmail.com',
url='https://github.com/bifs',
license=license,
packages=['bifs'],
author_email='john.kornak@ucsf.edu',
url='https://github.com/bifs/bifs',
license='BSD',
package_dir={'': 'src'},
package_data={'bifs': ['images/*']},
include_package_data=True,
scripts=['src/bifs/gui/bifs_gui.py'],
entry_points = {
'console_scripts': ['bifs_gui=bifs.gui.bifs_gui:main'],
},
packages=packages_,
# packages=find_packages(where='src') # does not work for me.

install_requires=['imageio',
'jsonpickle',
'matplotlib',
'nibabel',
'numpy',
'PyQt5',
'scipy']
'scipy'],
# Option items:
# extras_require={...},
# data_files=[(...)],

classifiers=[
# How mature is this project? Common values are
# 3 - Alpha; 4 - Beta; 5 - Production/Stable
'Development Status :: 3 - Alpha',

# Indicate who your project is intended for
'Intended Audience :: Developers',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Bio-Informatics',
'Topic :: Scientific/Engineering :: Image Recognition',

# Pick your license as you wish (should match "license" above)
'License :: OSI Approved :: BSD License',

# Specify the Python versions you support here.
# I assume we only support Python 3 and recent version.
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
],
keywords='Bayesian Fourier Image development',
python_requires='>=3.5',
)

File renamed without changes.
1 change: 1 addition & 0 deletions src/bifs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Empty file added src/bifs/bases/__init__.py
Empty file.
File renamed without changes.
11 changes: 4 additions & 7 deletions bifs/src/bifs_cl_1D.py → src/bifs/bifs_cl_1D.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# A command line type example for using BIFS example

import numpy as np
import scipy as sp
from scipy import misc,stats
import random
from pylab import *
from scipy import stats
import matplotlib.pyplot as plt
import bifs
import bifs_util.util as bu
from bifs.bifs_core import Bifs
from bifs.bifs_util import util as bu

# Make 1D "image"
# Noise standard deviation in image space
Expand All @@ -18,7 +15,7 @@
y = z + stats.norm.rvs(size=len(z),loc=0.0,scale=noiseSD)

# Create mybifs BIFS object:
mybifs = bifs.bifs()
mybifs = Bifs()

# Can take a look at what functions and variables are available with, e.g.:
# dir(mybifs)
Expand Down
Loading