Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/murfey/util/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ class GridSquareParameters(BaseModel):
tag: str
image: str = ""

# Actual coordinates for image centre in real space
x_location: Optional[float] = None
y_location: Optional[float] = None

# Image coordinates when overlaid on atlas (in pixels0)
# Coordinates for image centre when overlaid on atlas (in pixels)
x_location_scaled: Optional[int] = None
y_location_scaled: Optional[int] = None

Expand Down
50 changes: 33 additions & 17 deletions src/murfey/workflows/clem/register_preprocessing_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,12 @@ def _register_clem_imaging_site(
thumbnail_height / result.pixels_y, thumbnail_width / result.pixels_x
)
clem_img_site.thumbnail_pixel_size = result.pixel_size / scaling_factor
clem_img_site.thumbnail_pixels_x = int(result.pixels_x * scaling_factor)
clem_img_site.thumbnail_pixels_y = int(result.pixels_y * scaling_factor)
clem_img_site.thumbnail_pixels_x = (
int(round(result.pixels_x * scaling_factor)) or 1
)
clem_img_site.thumbnail_pixels_y = (
int(round(result.pixels_y * scaling_factor)) or 1
)
murfey_db.add(clem_img_site)
murfey_db.commit()
murfey_db.close()
Expand Down Expand Up @@ -354,30 +358,42 @@ def _register_grid_square(
and clem_img_site.y0 is not None
and clem_img_site.y1 is not None
):
# Find pixel corresponding to image midpoint on atlas
x_mid_real = (
0.5 * (clem_img_site.x0 + clem_img_site.x1) - atlas_entry.x0
)
# Find the real coordinates of the image midpoint
x_mid_real = 0.5 * (clem_img_site.x0 + clem_img_site.x1)
y_mid_real = 0.5 * (clem_img_site.y0 + clem_img_site.y1)

# Find pixel coordinates corresponding to image midpoint on atlas
x_mid_px = int(
x_mid_real / atlas_width_real * atlas_entry.thumbnail_pixels_x
)
y_mid_real = (
0.5 * (clem_img_site.y0 + clem_img_site.y1) - atlas_entry.y0
round(
(x_mid_real - atlas_entry.x0)
/ atlas_width_real
* atlas_entry.thumbnail_pixels_x
)
)
y_mid_px = int(
y_mid_real / atlas_height_real * atlas_entry.thumbnail_pixels_y
round(
(y_mid_real - atlas_entry.y0)
/ atlas_height_real
* atlas_entry.thumbnail_pixels_y
)
)

# Find the size of the image, in pixels, when overlaid on the atlas
width_scaled = int(
(clem_img_site.x1 - clem_img_site.x0)
/ atlas_width_real
* atlas_entry.thumbnail_pixels_x
round(
(clem_img_site.x1 - clem_img_site.x0)
/ atlas_width_real
* atlas_entry.thumbnail_pixels_x
)
or 1
)
height_scaled = int(
(clem_img_site.y1 - clem_img_site.y0)
/ atlas_height_real
* atlas_entry.thumbnail_pixels_y
round(
(clem_img_site.y1 - clem_img_site.y0)
/ atlas_height_real
* atlas_entry.thumbnail_pixels_y
)
or 1
)
else:
logger.warning(
Expand Down
Loading