Pad images with 0 on right and bottom, if images differ in dimensions#371
Pad images with 0 on right and bottom, if images differ in dimensions#371MSHelm wants to merge 7 commits intoscverse:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #371 +/- ##
==========================================
+ Coverage 61.85% 62.31% +0.45%
==========================================
Files 26 26
Lines 3138 3163 +25
==========================================
+ Hits 1941 1971 +30
+ Misses 1197 1192 -5
🚀 New features to boost your workflow:
|
|
@LucaMarconato did you find time to have a look at this PR yet? I think it would be really helpful to bring spatialdata-io on par with harpy. |
|
Hi @MSHelm, thanks for the PR, it looks good. I only made some minor code-style changes and expanded a bit on comments and docstrings. One extra thing that I noticed: harpy applies padding also on the top and left of the images https://github.com/saeyslab/harpy/blob/7907a0bf4515ccf19ca2659049213b865b245507/src/harpy/io/_macsima.py#L358, using information ( Could you comment on this please? Do you think that padding on the top left should be supported for some datasets? |
|
Hi @LucaMarconato , thank you for the review! The problem with the PR was, that internally I didnt find data sets that had this issue, so I had to rely solely on the single data set provided by @nbonine, which didnt have values aside from So long story short, for me that was the simplest, most intuitive solution, lacking a larger suite of test images to implement and verify a more sophisticated approach :) |
|
Hi @MSHelm , I also had a look at your PR. Internally, we had several datasets that stored a non-zero offset in the ome tiff metadata after preprocessing with MACSiQView software. In harpy we fetch it via this helper function https://github.com/saeyslab/harpy/blob/main/src/harpy/io/_macsima.py#L472. And then we do the following: pad_y_prepend = _translation[0] means: add that many blank rows before the image along the Y axis, i.e. above it. This effectively shifts the image downward on the shared canvas. pad_y_append = max_y - _size[0] means: add enough blank rows after the image along the Y axis, i.e. below it, so that this image reaches the same final height as all the others. And translations = _get_translations(imgs) So each image has an original height/width, plus a metadata-derived y, x offset. The code creates a common canvas large enough for all translated images. Note that _get_translations() substracts the minimum y/x positions, so the topmost/leftmost image starts at offset 0 (even if it would have translation y,x=(100,100). But that would be an edge case. The leftmost/topmost image always has offset 0, 0 in the metadata ). Unfortunately, I currently do not have a dataset available with this issue that I can publicly share. But I think it should be possible to create an artificial ome tiff with a non zero offset, in order to test this code branch. On a side note, I think there is a small typo here: you probably mean:
|
Fixes #366
The
macsimareader now first checks all image dimensions in X/Y. If there are mismatches, a warning is thrown, and the images are padded to the bottom/right with 0s.