Skip to content

Commit 123b56d

Browse files
committed
Cropping tool: fix occasional black borders in export at right/bottom
The image parts from all tiles/blocks are placed on the target canvas by the cropping tool. The locations of each image parts were slightly off, because the respective min/max locations in each tile was computed not as zero-based index but as one-based index. Additionally, the destination location of each part in the target canvas was accidentally computed wrongly, because it targeted the last pixel of the previous part as start of the new part, rather than targeting the next pixel to avoid an overlap. Both is fixed now.
1 parent 640c70d commit 123b56d

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ Miscellaneous:
215215
- Clicking the Home link in the upper left corner with a project open, will now
216216
also ask for confirmation (like clicking any data view entry in the menu).
217217

218+
- Cropping tool: in some exported sub volumes a black border of one or two
219+
pixels could appear on the right side and the bottom. This is fixed now and
220+
the entire space of the exported image is used correctly.
221+
218222
## Maintenance updates
219223

220224
- Node distance measurements: computation of straight line distance has been

django/applications/catmaid/control/cropping.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -490,23 +490,27 @@ def extract_substack_no_rotation(job) -> List:
490490
image_parts = []
491491
x_dst = bb.px_x_offset
492492
for nx, x in enumerate( range(tile_x_min, tile_x_max + 1) ):
493-
# The min x,y for the image part in the current tile are 0
494-
# for all tiles except the first one.
495-
cur_px_x_min = 0 if nx > 0 else bb.px_x_min - x * tile_width
496-
# The max x,y for the image part of current tile are the tile
497-
# size minus one except for the last one.
493+
# The min x,y index for the image part in the current tile are 0
494+
# for all tiles except the first one, where we can start within
495+
# a tile. In that case we also have to subtract one to make it
496+
# an index value (starting at 0).
497+
cur_px_x_min = 0 if nx > 0 else bb.px_x_min - x * tile_width - 1
498+
# The max x,y index for the image part of current tile are the
499+
# tile size minus one except for the last one. For instance, a
500+
# 64x63 tile will have a max x index of 63 (again, starting at 0).
498501
if nx < (num_x_tiles - 1):
499502
cur_px_x_max = tile_width - 1
500503
else:
501-
cur_px_x_max = bb.px_x_max - x * tile_width
504+
cur_px_x_max = bb.px_x_max - x * tile_width - 1
502505
# Reset y destination component
503506
y_dst = bb.px_y_offset
504507
for ny, y in enumerate( range(tile_y_min, tile_y_max + 1) ):
505-
cur_px_y_min = 0 if ny > 0 else bb.px_y_min - y * tile_height
508+
# Similar to cur_px_x_min above
509+
cur_px_y_min = 0 if ny > 0 else bb.px_y_min - y * tile_height - 1
506510
if ny < (num_y_tiles - 1):
507511
cur_px_y_max = tile_height - 1
508512
else:
509-
cur_px_y_max = bb.px_y_max - y * tile_height
513+
cur_px_y_max = bb.px_y_max - y * tile_height - 1
510514
# Create an image part definition
511515
z = bb.px_z_min + nz
512516
source_meta = job.get_source_metadata(stack, mirror, (x, y, z))
@@ -517,10 +521,14 @@ def extract_substack_no_rotation(job) -> List:
517521
except Exception as e:
518522
# ignore failed slices
519523
logger.error(f'An error happend while creating an impagepart: {e}')
520-
# Update y component of destination position
521-
y_dst += cur_px_y_max - cur_px_y_min
522-
# Update x component of destination position
523-
x_dst += cur_px_x_max - cur_px_x_min
524+
# Update y component of destination position. The next image
525+
# part should not begin with the max location of the current
526+
# part. Therefore, add one to the difference of min/max in
527+
# the current part.
528+
y_dst += cur_px_y_max - cur_px_y_min + 1
529+
# Update x component of destination position. The same applies
530+
# here as it does for y_dst above.
531+
x_dst += cur_px_x_max - cur_px_x_min + 1
524532

525533
# Write out the image parts and make sure the maximum allowed file
526534
# size isn't exceeded.

0 commit comments

Comments
 (0)