Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements for working with tiled segmentations #248

Merged
merged 20 commits into from
Nov 9, 2023
Merged

Conversation

CPBridge
Copy link
Collaborator

@CPBridge CPBridge commented Aug 30, 2023

A major set of improvements for working with segmentations of TILED images:

  • Add support for passing a total pixel matrix of a segmentation to the constructor. Previously, the user had to handle the process of creating the tiles from a total pixel matrix themselves as well as creating the plane positions that go along with this. This process is tedious, error-prone, and computationally inefficient especially with very large arrays. This PR add a tile_input_array boolean parameter. If it is True, the user passes a single frame to the constructor representing the full total pixel matrix, and highdicom performs the tiling automatically. The user may specify a tile_size, otherwise it will be copied from the source image. This process avoids unnecessarily reshaping the input array and should therefore also be considerably more efficient than reshaping to a stack of tiled frames before compressing/storing.
  • Add support for the TILED_FULL dimension organization type upon construction. The user can specify the dimension_organization_type as TILED_FULL and, if the requirements are met for this to be possible, the segmentation will be stored in this way. Note that I anticipate this primarily being used with the aforementioned tile_input_array option, though that is not a requirement. The previous behaviour was to use TILED_SPARSE (although this was not actually stored in the dataset) and store the frames in an order that was different to that required for TILED_FULL. Given comments in @hackermd 's existing code, I believe this was a mistake and that the intention was that frames should always have been stored in an order that matches TILED_FULL. Therefore I chose to change the order of frames for all segmentations to match that required by TILED_FULL regardless of whether the segmentation is actually stored as TILED_FULL. I suppose you could consider this a backwards incompatible change, although hopefully no-one was relying on the frame ordering in a non TILED_FULL. Also note that a clarification of the standard regarding where segment number should live in the TILED_FULL frame order has been prepared by @dclunie and I have followed this convention (segment number varies more slowly than row and column position).
  • Add a new method get_total_pixel_matrix to the segmentation object. This returns the segmentation array of a segmentation object as the total pixel matrix rather than a stack of frames. It works for both TILED_FULL and TILED_SPARSE (or unspecified dimension organization type). Furthermore, the user can specify a rectangular sub-region of the total pixel matrix rather than the full array. Otherwise, behaviour is similar to the existing methods for accessing the segmentation mask (the user may specify segments of interest and use the combine_segments option to have a labelmap style array returned to them). I implemented this by generalizing the underlying efficient segmentation "reconstruction" routine so most of the code is shared with the implementation of the existing methods.
  • In order to achieve the above there were several changes to the functions in the utils module. Previously the compute_plane_position_slide_per_frame function returned a list of PlanePositionObjects but for the tasks above it is inefficient to do this as we just want the underlying values stored in the objects. Therefore that method has been refactored to call another public function (iter_tiled_full_frame_data) that just yields the underlying data (plane positions and x/y/z offsets).
  • Documentation and tests for all of the above, including new sections in the Segmentation page of the user guide.

Note that currently this PR contains all of the contents of #245 as I branched from there.

@fedorov @dclunie @DanielaSchacherer @curtislisle

@CPBridge CPBridge changed the title TILED_FULL and auto-tiliing Improvements for working with tiled segmentations Sep 11, 2023
@CPBridge CPBridge added the enhancement New feature or request label Sep 11, 2023
@CPBridge CPBridge marked this pull request as ready for review September 11, 2023 22:46
@CPBridge CPBridge self-assigned this Sep 11, 2023
@DanielaSchacherer
Copy link

DanielaSchacherer commented Sep 12, 2023 via email

@CPBridge CPBridge merged commit 20c5e71 into v0.22.0dev Nov 9, 2023
@CPBridge CPBridge deleted the feat/autotile branch June 27, 2024 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants