Skip to content

Commit

Permalink
ref: code cleanup (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Apr 3, 2018
1 parent bc9d117 commit 54e2b3c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 64 deletions.
20 changes: 10 additions & 10 deletions radontea/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from .alg_bpj import backproject, backproject_3d
from .alg_fmp import fourier_map
from .alg_int import integrate
from .alg_art import art
from .alg_sart import sart
from .alg_bpj import backproject, backproject_3d # noqa F401
from .alg_fmp import fourier_map, fourier_map_3d # noqa F401
from .alg_int import integrate # noqa F401
from .alg_art import art # noqa F401
from .alg_sart import sart # noqa F401

from .fan import fan_rec, lino2sino
from .fan import fan_rec, lino2sino # noqa F401

from .rdn_prl import radon_parallel
from .rdn_fan import radon_fan
from .rdn_prl import radon_parallel # noqa F401
from .rdn_fan import radon_fan # noqa F401

from .threed import volume_recon
from .threed import volume_recon # noqa F401

from ._version import version as __version__
from ._version import version as __version__ # noqa F401


__author__ = u"Paul Müller"
Expand Down
1 change: 0 additions & 1 deletion radontea/alg_fmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,3 @@ def fourier_map_3d(sinogram, angles, intp_method="cubic",
count=count,
max_count=max_count,
ncpus=ncpus)

59 changes: 21 additions & 38 deletions radontea/logo.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,25 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
_logo.py
Functions that are used to create the logo of radontea.
"""
from __future__ import division

"""Functions that are used to create the logo of radontea."""
import numpy as np

if __name__ == "__main__":
from _Radon import radon # @UnusedImport
else:
from ._Radon import radon # @Reimport
from radontea import radon_parallel


def logo(x, y, N):
"""
Vector representation of radonteach logo.
"""Vector representation of radontea logo.
Parameters
----------
x,y : ndarray or float
coordinates where to calculate the logo.
N : float
total size of the image (NxN)
Parameters
----------
x,y: ndarray or float
coordinates where to calculate the logo.
N: float
total size of the image (NxN)
Returns
-------
v : ndarray
inverted values of the logo at the coordinates (x,y)
normalized to one.
Returns
-------
v: ndarray
inverted values of the logo at the coordinates (x,y)
normalized to one.
"""
z1 = np.exp(-((x - N / 8)**2 + (y + N / 14)**2) / (N / 8)**2)
z2 = np.exp(-((x + N / 10)**2 + (y - N / 10)**2) / (N / 8)**2)
Expand All @@ -50,10 +37,7 @@ def logo(x, y, N):


def get_original(N=64):
"""
Returns a two-dimensional square image that is the image used
to create the sinogram for the radontea logo.
"""
"""radontea logo base image"""
x = np.linspace(-N / 2, N / 2, N, endpoint=False)
X = x.reshape(1, -1)
Y = x.reshape(-1, 1)
Expand All @@ -63,24 +47,23 @@ def get_original(N=64):


def get_logo(N=64):
"""
Returns a two-dimensional square logo of resolution NxN. This
function discretizes the vector image representation of the
radonteach logo.
"""Return the radontea logo as a 2D NxN array
This function discretizes the vector image representation of the
radonteach logo.
"""
a = (get_original(N=N))
angles = np.linspace(0, np.pi * 1.6, N)
sinogram = radon(a, angles)
sinogram = radon_parallel(a, angles)
sinogram = (1 - sinogram / sinogram.max()) * 255
return sinogram.transpose()


def main():
# Show the logo
from matplotlib import pylab as plt
from matplotlib import cm
logo = get_logo(N=128)
plt.imshow(logo, cmap=cm.gray) # @UndefinedVariable
plt.imshow(logo, cmap="gray")
plt.axis("off")
plt.tight_layout()
plt.show()
Expand Down
23 changes: 8 additions & 15 deletions radontea/util.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Utility functions for radontea
"""
from __future__ import division, print_function

import numpy as np


def compute_angle_weights_1d(angles):
"""
Compute the weight for each angle according to the distance between its
neighbors.
Parameters
----------
angles : 1d ndarray of length A
angles: 1d ndarray of length A
Angles in radians
Returns
-------
weights : 1d ndarray of length A
weights: 1d ndarray of length A
The weights for each angle
Notes
-----
To compute the weights, the angles are set modulo PI, not modulo 2PI.
Expand All @@ -31,15 +24,15 @@ def compute_angle_weights_1d(angles):
"""
# copy and modulo np.pi
# This is an array with values in [0, np.pi)
angles = (angles.flatten() - angles.min()) % (np.pi)
angles = (angles.flatten() - angles.min()) % (np.pi)
# sort the array
sortargs = np.argsort(angles)
sortangl = angles[sortargs]
# compute weights for sorted angles
da = (np.roll(sortangl, -1) - np.roll(sortangl, 1)) % (np.pi)
weights = da/np.sum(da)*da.shape[0]

unsortweights = np.zeros_like(weights)
# Sort everything back where it belongs
unsortweights[sortargs] = weights
return unsortweights
return unsortweights

0 comments on commit 54e2b3c

Please sign in to comment.