Skip to content

Commit

Permalink
- fix: also guess initial values for image method if edge detection
Browse files Browse the repository at this point in the history
   is ill-defined (RadiusExceedsImageSizeError)
 - fix: constrict the position of the center to the image area when
   performing a circle fit to an edge
  • Loading branch information
paulmueller committed Sep 1, 2019
1 parent f04ff78 commit 09cb19a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
@@ -1,3 +1,8 @@
0.5.3
- fix: also guess initial values for image method if edge detection
is ill-defined (RadiusExceedsImageSizeError)
- fix: constrict the position of the center to the image area when
performing a circle fit to an edge
0.5.2
- fix: guess initial values for image method when edge detection
method fails
Expand Down
4 changes: 2 additions & 2 deletions qpsphere/cnvnc.py
Expand Up @@ -94,11 +94,11 @@ def analyze(qpi, r0, method="edge", model="projection", edgekw={}, imagekw={},
ret_center=True,
ret_edge=False,
)
except edgefit.EdgeDetectionError:
except (edgefit.EdgeDetectionError,
edgefit.RadiusExceedsImageSizeError):
# proceed with best guess
c0 = np.array(qpi.shape) / 2
n0 = qpi["medium index"] + np.sign(np.sum(qpi.pha)) * .01

res = imagefit.analyze(qpi=qpi,
model=model,
n0=n0,
Expand Down
4 changes: 2 additions & 2 deletions qpsphere/edgefit.py
Expand Up @@ -154,8 +154,8 @@ def circle_fit(edge, ret_dev=False):
params = lmfit.Parameters()
# initial parameters
sum_edge = np.sum(edge)
params.add("cx", np.sum(x * edge) / sum_edge)
params.add("cy", np.sum(y * edge) / sum_edge)
params.add("cx", np.sum(x * edge) / sum_edge, min=0, max=sx)
params.add("cy", np.sum(y * edge) / sum_edge, min=0, max=sy)
# data
xedge, yedge = np.where(edge)
# minimize
Expand Down

0 comments on commit 09cb19a

Please sign in to comment.