@@ -130,8 +130,8 @@ def _register_clem_imaging_site(
130130 thumbnail_height / result .pixels_y , thumbnail_width / result .pixels_x
131131 )
132132 clem_img_site .thumbnail_pixel_size = result .pixel_size / scaling_factor
133- clem_img_site .thumbnail_pixels_x = int (result .pixels_x * scaling_factor )
134- clem_img_site .thumbnail_pixels_y = int (result .pixels_y * scaling_factor )
133+ clem_img_site .thumbnail_pixels_x = int (round ( result .pixels_x * scaling_factor ) )
134+ clem_img_site .thumbnail_pixels_y = int (round ( result .pixels_y * scaling_factor ) )
135135 murfey_db .add (clem_img_site )
136136 murfey_db .commit ()
137137 murfey_db .close ()
@@ -354,30 +354,40 @@ def _register_grid_square(
354354 and clem_img_site .y0 is not None
355355 and clem_img_site .y1 is not None
356356 ):
357- # Find pixel corresponding to image midpoint on atlas
358- x_mid_real = (
359- 0.5 * (clem_img_site .x0 + clem_img_site .x1 ) - atlas_entry .x0
360- )
357+ # Find the real coordinates of the image midpoint
358+ x_mid_real = 0.5 * (clem_img_site .x0 + clem_img_site .x1 )
359+ y_mid_real = 0.5 * (clem_img_site .y0 + clem_img_site .y1 )
360+
361+ # Find pixel coordinates corresponding to image midpoint on atlas
361362 x_mid_px = int (
362- x_mid_real / atlas_width_real * atlas_entry .thumbnail_pixels_x
363- )
364- y_mid_real = (
365- 0.5 * (clem_img_site .y0 + clem_img_site .y1 ) - atlas_entry .y0
363+ round (
364+ (x_mid_real - atlas_entry .x0 )
365+ / atlas_width_real
366+ * atlas_entry .thumbnail_pixels_x
367+ )
366368 )
367369 y_mid_px = int (
368- y_mid_real / atlas_height_real * atlas_entry .thumbnail_pixels_y
370+ round (
371+ (y_mid_real - atlas_entry .y0 )
372+ / atlas_height_real
373+ * atlas_entry .thumbnail_pixels_y
374+ )
369375 )
370376
371377 # Find the size of the image, in pixels, when overlaid on the atlas
372378 width_scaled = int (
373- (clem_img_site .x1 - clem_img_site .x0 )
374- / atlas_width_real
375- * atlas_entry .thumbnail_pixels_x
379+ round (
380+ (clem_img_site .x1 - clem_img_site .x0 )
381+ / atlas_width_real
382+ * atlas_entry .thumbnail_pixels_x
383+ )
376384 )
377385 height_scaled = int (
378- (clem_img_site .y1 - clem_img_site .y0 )
379- / atlas_height_real
380- * atlas_entry .thumbnail_pixels_y
386+ round (
387+ (clem_img_site .y1 - clem_img_site .y0 )
388+ / atlas_height_real
389+ * atlas_entry .thumbnail_pixels_y
390+ )
381391 )
382392 else :
383393 logger .warning (
0 commit comments