Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Add tiling method from Disentangle repository (CAREamics#207)
### Description The Disentangle repository takes a slightly different approach to tiling results than the method in CAREamics. This PR reimplements the former's approach to ensure the reproduction of the results in the microSplit paper, in a way that should be compatible with the existing CAREamics prediction pipeline with minor refactoring. - **What**: Added a generator `extract_tiles` that yields the extracted tile and and tile information. This function is interchangeable with the existing `careamics.dataset.tiling.extract_tiles`. This means the resulting set of tiles can be passed to the existing `careamics.prediction_utils.stitch_prediction` to reconstruct the full image. The `InMemoryTiledPredDataset` can be refactored so the `extract_tiles` generator, can be chosen by the configuration. - **Why**: To ensure the reproduction of the results in the microSplit paper. - **How**: Moved relevant logic contained in the Disentangle classes [`GridIndexManager`](https://github.com/ashesh-0/Disentangle/blob/3dusplit/disentangle/data_loader/patch_index_manager.py) and [`MultiChDloader`](https://github.com/ashesh-0/Disentangle/blob/3dusplit/disentangle/data_loader/vanilla_dloader.py) to a set of functions contained within the module `careamics/dataset/tiling/lvae_tiled_patching.py`. This includes the `compute_tile_info` function that computes a CAREamics compatible `TileInformation` object from a given tile's location. ### Changes Made - **Added**: - `careamics/dataset/tiling/lvae_tiled_patching.py` - `tests/dataset/tiling/test_lvae_tiled_patching.py` - `src/careamics/prediction_utils/lvae_tiling_manager.py` - This can be ignored. I started by refactoring the `GridIndexManager` class (renamed to `TilingManager`). It is unused because I decided to create a functional implementation, more inline with what already exists in CAREamics. However, I have left it in, commented out, in case it is useful for the dataset implementation. ### Additional Notes and Examples Bit extra, but diagrams below demonstrate the difference between the two tiling methods. The grey area in the diagram illustrates where padding has been added to array. The Disentangle method ensures the stitched portion of a tile comes from the center. ![CAREamics_tiling](https://github.com/user-attachments/assets/1db2b00d-a8fc-47f7-ae2c-07af04f275bf) ![Asheshs_tiling](https://github.com/user-attachments/assets/3c3700dd-c48d-4fe7-933e-12200adbe6a7) #### Where to find original logic `extract_tiles` logic mostly comes from: https://github.com/ashesh-0/Disentangle/blob/ed99b2614a9e52b496947ccf157d3aaa8db52872/disentangle/data_loader/vanilla_dloader.py#L435-L465 Calculation of `overlap_crop_coords` and `stitch_coords` in `compute_tile_info` comes from: https://github.com/ashesh-0/Disentangle/blob/ed99b2614a9e52b496947ccf157d3aaa8db52872/disentangle/analysis/stitch_prediction.py#L36-L66 All other helper functions are a reimplementation of the logic in the methods of `GridIndexManager`. #### Note We should come with a better name for the two different approaches to avoid name clashes. --- **Please ensure your PR meets the following requirements:** - [x] Code builds and passes tests locally, including doctests - [x] New tests have been added (for bug fixes/features) - [x] Pre-commit passes - [ ] PR to the documentation exists (for bug fixes / features) --------- Co-authored-by: Joran Deschamps <6367888+jdeschamps@users.noreply.github.com>
- Loading branch information