Skip to content

Pixel Sizes - #3045

Merged
btbest merged 12 commits into
ilastik:mainfrom
Peter-Laszcz:pixelsize
Oct 1, 2025
Merged

btbest merged 12 commits into
ilastik:mainfrom
Peter-Laszcz:pixelsize

Conversation

@Peter-Laszcz

@Peter-Laszcz Peter-Laszcz commented Jul 22, 2025 •

Copy link
Copy Markdown
Contributor

Add support for importing/exporting pixel size metadata via TIFF/OME-TIFF.

The addition of this feature would allow the development of features specified in #3029 as well as being a fundamental first step in solving issues #967 and #2870 .

GSoC Submission:

This PR is my main code submission; you can also find a blog on the process here, as well as a PR for documentation update here. In one route to implement this feature, I contributed PRs to both Ilastik and VIGRA; that particular route ultimately failed due to forwards compatibility issues, but you can find the closed PRs here and here.

The main goal of the project was to implement the reading and writing of pixel sizes in Ilastik via TIFF files. This pull request achieves that goal. There were some significant challenges in achieving this (which are detailed in the blog), hence a lack of extension features, but I am working on and intend to contribute features utilising pixel sizes beyond GSoC 2025.

Checklist

  • Format code and imports.
  • Add docstrings and comments.
  • Add tests.
  • Reference relevant issues and other pull requests.
  • Rebase commits into a logical sequence.

@codecov

codecov Bot commented Jul 23, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.48276% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.84%. Comparing base (d415c90) to head (7773b98).
⚠️ Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
...ets/dataSelection/datasetDetailedInfoTableModel.py 32.00% 17 Missing ⚠️
lazyflow/operators/ioOperators/opTiffReader.py 97.72% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3045   +/-   ##
=======================================
  Coverage   62.84%   62.84%           
=======================================
  Files         530      531    +1     
  Lines       64042    64118   +76     
=======================================
+ Hits        40245    40297   +52     
- Misses      23797    23821   +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Peter-Laszcz
Peter-Laszcz marked this pull request as ready for review July 23, 2025 13:59
@Peter-Laszcz Peter-Laszcz reopened this Aug 7, 2025

@btbest btbest left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exported a tiff and got this. Looks like there's at least one test missing to make sure this doesn't happen :)

I think we should sit together for tests at some point, but I've put pointers as mentioned earlier today for now.

image

@btbest
btbest requested a review from k-dominik August 25, 2025 13:32

@btbest btbest left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome to finally see pixel size metadata in ilastik 🥳

A few minor things from my side, mostly nitpicks. And I'm excited to see your draft work using the new metadata once it's rebased ;)

@k-dominik k-dominik left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @Peter-Laszcz - really solid work! Nicely tested, too. I had a few comments - some of them are taste :). @btbest, maybe you want to weigh in on those. Really critical for me right now is documenting the changes to the zipped projects (as this is hard to follow otherwise), and maybe the default dictionary value in DatasetInfo.

Another thought experiment: Say I export a subregion - one of the axes becomes singleton and I chose to drop it, would the metadata reflect this accurately in all file formats?

@Peter-Laszcz

Copy link
Copy Markdown
Contributor Author

Hello @Peter-Laszcz - really solid work! Nicely tested, too. I had a few comments - some of them are taste :). @btbest, maybe you want to weigh in on those. Really critical for me right now is documenting the changes to the zipped projects (as this is hard to follow otherwise), and maybe the default dictionary value in DatasetInfo.

Another thought experiment: Say I export a subregion - one of the axes becomes singleton and I chose to drop it, would the metadata reflect this accurately in all file formats?

Just tried it and came up with an interesting result. Ilastik exports the correct pixel sizes to the correct areas in the metadata, but FIJI can't read it properly:

image

Checking with tifffile, these fields appear to have the correct numbers and format. One thing I did notice - not sure if it's any bearing on what's going on here- was that Ilastik seems to have added in a channel axis which has shifted the image data along one axis, i.e. the image was meant to have an XY axis set and shape of (16,16) but has been exported with an axis set of CYX and a shape of (16,16,2), also producing the unfortunate side effect of the X axis being listed as having a length of 2 in the metadata :/

@Peter-Laszcz

Peter-Laszcz commented Sep 8, 2025 •

Copy link
Copy Markdown
Contributor Author

To update on the issue I came across- it was actually the manifestation of three separate problems:

  1. The negative resolutions were being caused by the tifffile library picking fractions with extremely high denominators, as a result of feeding in the resolutions as floats. This was remedied by calculating more sensible fractions with the Fraction library (with an upper limit less than that of uint32 to avoid more overflows) and feeding them directly into tifffile.
  2. The output axes of 2D images I was producing was CYX, whereas otherwise they would have the axis order YXS. This is because when Vigra's impex is used to write images, it writes the axes "as-is" (i.e. yxc), and stores the C axis as the S axis. It reverts this choice of axis on the reading end when the "S" axis is assigned the axis key "c" upon creating axistags. Hence at the moment ilastik exports 2d images as YXS. As we are using tifffile to export TIFFs with axis units, the 2d exporter pushes the "TZCYX" format (and therefore would export the axes CYX), which is also currently used by Ilastik to export TIFF hyperstacks. It is definitely a good idea to discuss whether changing the 2d exported axis order to include units and match hyperstack axis order would be a safe move, in terms of if any critical systems using Ilastik rely on a strict 2d axis order.
  3. The previous point also caused an axis mismatch between CYX and YXS; this has been solved in the most recent commits by setting the correct axis order

@Peter-Laszcz

Copy link
Copy Markdown
Contributor Author

Hello! After tidying up the commits, I think this PR is ready for another review :)
To summarise, the main changes to the codebase so far have been:

  • Modifying opTiffReader to recognise and copy pixel size metadata to slot meta
  • Modifying opExportMultipageTiff to export pixel size metadata where it exists
  • Adding pixel size fields to h5 readers and writers (with the primary purpose of saving and loading to project files, but added benefit of exporting and loading pixel sizes from h5)
  • Adding column to GUI table to display pixel sizes
  • Added relevant tests (including an extra test project in test_projects.zip)

As per last week's meeting, I've removed all the functionality for exporting pixel sizes via opExport2DImage ("tiff" in export format), to potentially be replaced by a specialised format in the future. Note, however, that one should still be able to obtain 2D TIFFs with pixel sizes via opExportMultipageTiff ("multipage tiff" in export format), so until then there's a good workaround.

@k-dominik k-dominik left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow that is some clean git history :) Must have been a fun rebase. Thank you for going through that!

Really solid work with exemplary test coverage.

On the danger of being incredibly annoying I found a case that I would expect to work, not working:

Exporting to hdf5 (probabilities from pixel classification) (very cool with units now) and loading this data as raw data seems to fail if the input has no channel axes (then, no unit gets written, but ui seems to expect it to be there for all the axes):

screenshot image
traceback
ERROR 2025-09-16 16:05:57,750 excepthooks 46725 8611815616 Traceback (most recent call last):
  File "...ilastik/ilastik/applets/dataSelection/datasetDetailedInfoTableModel.py", line 145, in data
    return self._getDisplayRoleData(index)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...ilastik/ilastik/applets/dataSelection/dataLaneSummaryTableModel.py", line 75, in _getDisplayRoleData
    return model_cls._getDisplayRoleData(self, index)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...ilastik/ilastik/applets/dataSelection/datasetDetailedInfoTableModel.py", line 232, in _getDisplayRoleData
    axis_strings = [
                   ^
  File "...ilastik/ilastik/applets/dataSelection/datasetDetailedInfoTableModel.py", line 242, in <listcomp>
    if tag.resolution or datasetInfo.axis_units[tag.key]
                         ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
KeyError: 'c'

example data: blobs.zip

@Peter-Laszcz

Copy link
Copy Markdown
Contributor Author

Exporting to hdf5 (probabilities from pixel classification) (very cool with units now) and loading this data as raw data seems to fail if the input has no channel axes (then, no unit gets written, but ui seems to expect it to be there for all the axes):
screenshot
traceback

ERROR 2025-09-16 16:05:57,750 excepthooks 46725 8611815616 Traceback (most recent call last):
  File "...ilastik/ilastik/applets/dataSelection/datasetDetailedInfoTableModel.py", line 145, in data
    return self._getDisplayRoleData(index)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...ilastik/ilastik/applets/dataSelection/dataLaneSummaryTableModel.py", line 75, in _getDisplayRoleData
    return model_cls._getDisplayRoleData(self, index)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...ilastik/ilastik/applets/dataSelection/datasetDetailedInfoTableModel.py", line 232, in _getDisplayRoleData
    axis_strings = [
                   ^
  File "...ilastik/ilastik/applets/dataSelection/datasetDetailedInfoTableModel.py", line 242, in <listcomp>
    if tag.resolution or datasetInfo.axis_units[tag.key]
                         ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
KeyError: 'c'

example data: blobs.zip

This happened because I was allowing channel axes to display pixel sizes, because there is a niche case where someone could potentially write a unit to the channel axis in the h5 format. However, after some thought, the commit I am pushing to fix this will stop channel pixel sizes from appearing in the data table, mainly as anything written in that field would not be used/manipulable in ilastik in any way I can fathom (however, the data is still passed through the pipeline so if a use case emerges it's somewhat futureproof)

@k-dominik

k-dominik commented Sep 24, 2025 •

Copy link
Copy Markdown
Contributor

I probably wouldn't mind showing the unit value for the c axis if it's there, but let's leave it as is. For the circleCI failure you probably need to merge main into this PR again (vaguely remember running into this and fixing it). Also cool the added units for the ome export - would you say this is more or less complete now @Peter-Laszcz?

@Peter-Laszcz

Copy link
Copy Markdown
Contributor Author

would you say this is more or less complete now @Peter-Laszcz?
Definitely- as soon as circleCI stops segfaulting 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants