Skip to content

Commit

Permalink
v2.0.11.3 (#61)
Browse files Browse the repository at this point in the history
* Fixed bug: Edge case of incorrect positioning of scatterer.
  • Loading branch information
giovannivolpe authored Jul 27, 2021
1 parent dc67a9c commit f4f4abc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions deeptrack/optics.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .image import Image, pad_image_to_fft
from .types import ArrayLike, PropertyLike

import scipy.ndimage
from scipy.ndimage import convolve


Expand Down Expand Up @@ -555,7 +556,7 @@ def get(self, illuminated_volume, limits, fields, **kwargs):

K = 2 * np.pi / kwargs["wavelength"]

field_z = [_get_position(field, return_z=True)[-1] for field in fields]
field_z = [field.get_property("z") for field in fields]
field_offsets = [field.get_property("offset_z", default=0) for field in fields]

z = z_limits[1]
Expand Down Expand Up @@ -687,12 +688,13 @@ def _get_position(image, mode="corner", return_z=False):
# Extracts the position of the upper left corner of a scatterer
num_outputs = 2 + return_z

if mode == "corner":
# Probably unecessarily complicated expression
shift = (
np.ceil((np.array(image.shape) - 1) / 2)
- (1 - np.mod(image.shape, 2)) * 0.5
)
if mode == "corner" and image.size > 0:

shift = scipy.ndimage.measurements.center_of_mass(np.abs(np.array(image)))

if np.isnan(shift).any():
shift = np.array(image.shape) / 2

else:
shift = np.zeros((num_outputs))

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

setuptools.setup(
name="deeptrack", # Replace with your own username
version="0.11.0",
version="0.11.3",
author="Benjamin Midtvedt",
author_email="[email protected]",
description="A deep learning oriented microscopy image simulation package",
Expand Down

0 comments on commit f4f4abc

Please sign in to comment.