Skip to content

Commit

Permalink
binary meanings now propagated throughout; plots updated accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
bpops committed Aug 5, 2023
1 parent 537ca00 commit 7423c8f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

CodedApertures is a python module that allows one to easily generate and display common coded aperture patterns. Coded apertures are a spatial encoding technique for straight-line optics, wherein traditional lensing (e.g., visible light) is not possible. Even wherein tradiational lensing is possible, there may be other advantages (infinite depth of field). Coded apertures may therefore be used for hard x-ray and gamma-ray imaging for astrophysics, medical imaging, and homeland security applications.

New to coded apertures? Here's a nice article: https://www.paulcarlisle.net/codedaperture/
New to coded apertures? Here's a nice article: https://www.paulcarlisle.net/codedaperture/.

### Usage

Expand Down
38 changes: 19 additions & 19 deletions codedapertures/codedapertures.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,11 @@ def __init__(self, rank=4, r=5, radius=5, quiet=False):
self.l[i,j] = (i_idx + self.r*j_idx) % self.v

# calculate mask
self.mask = np.zeros(self.l.shape, dtype=np.int16)
self.mask = np.zeros(self.l.shape, dtype=np.int16)+1
for i in range(self.mask.shape[0]):
for j in range(self.mask.shape[1]):
if self.l[i,j] in self.D:
self.mask[i,j] = 1
self.mask[i,j] = 0

# map to axial matrix
for i in range(self.diam):
Expand Down Expand Up @@ -554,9 +554,9 @@ def show_rhombus(self, labels=False, labelsize=10):

# add hexagon
if self.mask[x_i,y_i] == 1:
facecolor='k'
else:
facecolor='w'
else:
facecolor='k'
hex = RegularPolygon((x, y), numVertices=6, radius=hex_radius,
orientation=np.radians(60),
facecolor=facecolor, alpha=0.6, edgecolor='k')
Expand Down Expand Up @@ -596,8 +596,8 @@ def show(self, labels=False, labelsize=10):
row_width = self.diam - abs(self.radius-y)
start_i = np.max((self.radius-y,0))
for x in range(row_width):
facecolor = 'k' if self.axial_matrix[x+start_i,y] == 1 else 'w'
alpha = 0.9 if self.axial_matrix[x+start_i,y] == 1 else 0.3
facecolor = 'w' if self.axial_matrix[x+start_i,y] == 1 else 'k'
alpha = 0.3 if self.axial_matrix[x+start_i,y] == 1 else 0.9
label = self.l[x+start_i,y]
hex = RegularPolygon((x+0.5*abs(y-self.radius)-self.radius,
((y-self.radius)*((3/2)*hex_vert/2.0))),
Expand Down Expand Up @@ -665,11 +665,11 @@ def __init__(self, rank=4, radius=5, quiet=False):
self.l[i,j] = (i_idx + self.r*j_idx) % self.v

# calculate mask
self.mask = np.zeros(self.l.shape, dtype=np.int16)
self.mask = np.zeros(self.l.shape, dtype=np.int16)+1
for i in range(self.mask.shape[0]):
for j in range(self.mask.shape[1]):
if self.l[i,j] in self.D:
self.mask[i,j] = 1
self.mask[i,j] = 0

# map to axial matrix
for i in range(self.diam):
Expand Down Expand Up @@ -768,9 +768,9 @@ def show_rhombus(self, labels=False, labelsize=10):

# add hexagon
if self.mask[x_i,y_i] == 1:
facecolor='k'
else:
facecolor='w'
else:
facecolor='k'
hex = RegularPolygon((x, y), numVertices=6, radius=hex_radius,
orientation=np.radians(60),
facecolor=facecolor, alpha=0.6, edgecolor='k')
Expand Down Expand Up @@ -810,8 +810,8 @@ def show(self, labels=False, labelsize=10):
row_width = self.diam - abs(self.radius-y)
start_i = np.max((self.radius-y,0))
for x in range(row_width):
facecolor = 'k' if self.axial_matrix[x+start_i,y] == 1 else 'w'
alpha = 0.9 if self.axial_matrix[x+start_i,y] == 1 else 0.3
facecolor = 'w' if self.axial_matrix[x+start_i,y] == 1 else 'k'
alpha = 0.3 if self.axial_matrix[x+start_i,y] == 1 else 0.9
label = self.l[x+start_i,y]
hex = RegularPolygon((x+0.5*abs(y-self.radius)-self.radius,
((y-self.radius)*((3/2)*hex_vert/2.0))),
Expand Down Expand Up @@ -852,7 +852,7 @@ def __init__(self, radius=3, fill=0.5, quiet=False):
self.radius = radius
self.diam = self.radius*2+1
self.side_width = radius + 1
self.axial_matrix = np.zeros((self.diam,self.diam))
self.axial_matrix = np.zeros((self.diam,self.diam))+1
self.loc_matrix = np.zeros((2,self.diam,self.diam))
self.fill = fill

Expand All @@ -861,12 +861,12 @@ def __init__(self, radius=3, fill=0.5, quiet=False):
for j in range(self.diam):
if (i+j > (self.radius-1)) and (i+j < (self.diam+self.radius)):
if random.random() < self.fill:
self.axial_matrix[i,j] = 1
self.axial_matrix[i,j] = 0
else:
self.axial_matrix[i,j] = np.nan

# determine actual fill factor
self.actual_fill = np.sum(self.axial_matrix == 1) / np.sum(~np.isnan(self.axial_matrix))
self.actual_fill = 1- (np.sum(self.axial_matrix == 1) / np.sum(~np.isnan(self.axial_matrix)))

# generate locations
for i in range(self.diam):
Expand Down Expand Up @@ -904,8 +904,8 @@ def show(self):
row_width = self.diam - abs(self.radius-y)
start_i = np.max((self.radius-y,0))
for x in range(row_width):
facecolor = 'k' if self.axial_matrix[x+start_i,y] == 1 else 'w'
alpha = 0.6 if self.axial_matrix[x+start_i,y] == 1 else 0.3
facecolor = 'w' if self.axial_matrix[x+start_i,y] == 1 else 'k'
alpha = 0.3 if self.axial_matrix[x+start_i,y] == 1 else 0.9
hex = RegularPolygon((x+0.5*abs(y-self.radius)-self.radius,
((y-self.radius)*((3/2)*hex_vert/2.0))),
numVertices=6, radius=hex_vert/2.0,
Expand Down Expand Up @@ -981,8 +981,8 @@ def show(self, inverse=False, size=5):
size of the plot (default 8)
"""
plt.rcParams['figure.figsize'] = [size,size]
cmap = "binary_r" if inverse else "binary"
plt.imshow(self.mask, cmap="gray", origin='lower', aspect=1)
cmap = "binary" if inverse else "binary_r"
plt.imshow(self.mask, cmap=cmap, origin='lower', aspect=1)
plt.axis('off')
plt.title(f"Pseudo-Noise Product Array [m: {self.m}, n: {self.n}]")
plt.show()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import setuptools

setuptools.setup(name='codedapertures',
version='0.7.1',
version='0.8',
description='a python package for generating coded apertures',
long_description='CodedApertures is a python package that allows one to easily generate and display common coded aperture patterns. Coded apertures are a spatial encoding technique for straight-line optics, wherein traditional lensing (e.g., visible light) is not possible. Even wherein tradiational lensing is possible, there may be other advantages (infinite depth of field). Coded apertures may therefore be used for hard x-ray and gamma-ray imaging for astrophysics, medical imaging, and homeland security applications.',
url='https://github.com/bpops/codedapertures',
Expand Down

0 comments on commit 7423c8f

Please sign in to comment.