Skip to content

Commit

Permalink
Remove dependency on physical_dim parameter in GMRF for CUQI CT (#79)
Browse files Browse the repository at this point in the history
* Remove dependancy on physical_dim paramter in GMRF

* Use Image2D without visual_only for forward model by creating functions to evaluate input image and output image in CUQI-CT
  • Loading branch information
nabriis authored May 23, 2024
1 parent baeec7f commit f9763b5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
22 changes: 13 additions & 9 deletions benchmarks/cuqi-ct/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,21 @@ def __init__(self, name):

Amat = dx*Amat

# Create the CUQIpy linear model
A = LinearModel(Amat)
# Create Image2D geometries of image and sinogram spaces
dg = Image2D(( N,N))
rg = Image2D((nv,N))

# Define forward and adjoint operators (working on images)
def forward(x):
y = Amat @ x.ravel()
return y.reshape((nv, N))

# Create the visual_only Image2D geometries of image and sinogram spaces
dg = Image2D(( N,N), visual_only=True)
rg = Image2D((nv,N), visual_only=True)
def adjoint(y):
x = Amat.T @ y.ravel()
return x.reshape((N, N))

# Equip linear operator with geometries
A.domain_geometry = dg
A.range_geometry = rg
# Create the CUQIpy linear model
A = LinearModel(forward=forward, adjoint=adjoint, range_geometry=rg, domain_geometry=dg)

# Create the CUQI data structure from vectorized image and geometry
imC = CUQIarray(data["exact"], geometry=dg)
Expand Down Expand Up @@ -127,7 +132,6 @@ def __init__(self):
super().__init__(self.__class__.__name__)
self.prior = GMRF(np.zeros(self.dim),
lambda delta: 1 / delta,
physical_dim=2,
geometry=self.likelihood.geometry,
name="x")

Expand Down
20 changes: 14 additions & 6 deletions benchmarks/cuqi-ct/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,21 @@

Amat = dx*Amat

# Create the CUQIpy linear model
A = LinearModel(Amat)
# Create Image2D geometries of image and sinogram spaces
dg = Image2D(( N,N))
rg = Image2D((nv,N))

# Define forward and adjoint operators (working on images)
def forward(x):
y = Amat @ x.ravel()
return y.reshape((nv, N))

# Create the visual_only Image2D geometries of image and sinogram spaces
dg = Image2D(( N,N), visual_only=True)
rg = Image2D((nv,N), visual_only=True)
def adjoint(y):
x = Amat.T @ y.ravel()
return x.reshape((N, N))

# Create the CUQIpy linear model
A = LinearModel(forward=forward, adjoint=adjoint, range_geometry=rg, domain_geometry=dg)

# Equip linear operator with geometries
A.domain_geometry = dg
Expand Down Expand Up @@ -132,7 +141,6 @@
assert output_Gaussian == pytest.approx(BP.posterior.logpdf(parameters))

BP.prior = cuqi.distribution.GMRF(np.zeros(256**2), 1/(0.01),
physical_dim=2,
geometry=BP.likelihood.geometry)
assert output_GMRF == pytest.approx(BP.posterior.logpdf(parameters))

Expand Down

0 comments on commit f9763b5

Please sign in to comment.