catalystneuro / roiextractors

Python-based module for extracting from, converting between, and handling optical imaging data from several file formats. Inspired by SpikeInterface.
https://roiextractors.readthedocs.io/en/latest/index.html
BSD 3-Clause "New" or "Revised" License
12 stars 7 forks source link

Add function to extract ROIs metadata from ScanImage tiff #272

Closed alessandratrapani closed 9 months ago

alessandratrapani commented 9 months ago

In the ScanImage .tif metadata there is a dictonary saved as text that the function extract_extra_metadata cannot parse, where information on the ROIs are stored. I implemented a new function call extract_roi_metadata (https://github.com/catalystneuro/roiextractors/pull/272) that return this dict.

"RoiGroups":{
    "imagingRoiGroup":{# general imaging space metadata (only 2D)
        ...
        "centerXY": [-1.776356839e-16,0.1],
        "sizeXY": [13.5,13.5], # size of the FOV in micrometers
        "rotationDegrees": 0,
        "enable": 1,
        "pixelResolutionXY": [512,512],
        "pixelToRefTransform": [[0.0263671875,0,-6.763183594],
                                [0,0.263671875,-6.663183594],
                                [0,0,1]],
        "affine":  [[13.5,0,-6.75],
                    [0,13.5,-6.65],
                    [0,0,1]]
        ...
    },
    "integrationRoiGroup":{
        ...
        "rois": [
        {
          "ver": 1,
          "classname": "scanimage.mroi.Roi",
          "name": "ROI 1",
            ...
          "zs": 0,
          "scanfields": {
            ...
            "centerXY": [2.518066406,1.062402344],
            "sizeXY": [0.2373046875,0.2373046875],
            "rotationDegrees": 0,
            "enable": 1,
            "threshold": 100,
            "channel": 1,
            "processor": "cpu",
            "mask": [roi_pixel_mask 9x9 binary matrix],
            "affine": [[0.2373046875,0,2.518066406],
                       [0,0.2373046875,1.062402344],
                       [0,0,1]]
          },
          "discretePlaneMode": 1,
          "powers": null,
          "pzAdjust": null,
          "Lzs": null,
          "interlaceDecimation": null,
          "interlaceOffset": null,
          "enable": 1
        },
        ... # all the 368 ROIs
        ]
    } # imaging space metadata for each ROI
}

From imagingRoiGroup we can extract info on the dimension of the field of view (XY) from "sizeXY" and divide by the dimension to get the grid_spacing (z dimension missed)

In integrationRoiGroup we can extract information about the position of the rois: inv(pixelToRefTransform)*centerXY

codecov[bot] commented 9 months ago

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (bd18e5b) 79.19% compared to head (44194b3) 79.00%. Report is 1 commits behind head on main.

:exclamation: Current head 44194b3 differs from pull request most recent head 1d385ee. Consider uploading reports for the commit 1d385ee to get more accurate results

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/catalystneuro/roiextractors/pull/272/graphs/tree.svg?width=650&height=150&src=pr&token=UA958XVSZP&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=catalystneuro)](https://app.codecov.io/gh/catalystneuro/roiextractors/pull/272?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=catalystneuro) ```diff @@ Coverage Diff @@ ## main #272 +/- ## ========================================== - Coverage 79.19% 79.00% -0.20% ========================================== Files 39 39 Lines 3057 3067 +10 ========================================== + Hits 2421 2423 +2 - Misses 636 644 +8 ``` | [Flag](https://app.codecov.io/gh/catalystneuro/roiextractors/pull/272/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=catalystneuro) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/catalystneuro/roiextractors/pull/272/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=catalystneuro) | `79.00% <20.00%> (-0.20%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=catalystneuro#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/catalystneuro/roiextractors/pull/272?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=catalystneuro) | Coverage Δ | | |---|---|---| | [...ctors/tiffimagingextractors/scanimagetiff\_utils.py](https://app.codecov.io/gh/catalystneuro/roiextractors/pull/272?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=catalystneuro#diff-c3JjL3JvaWV4dHJhY3RvcnMvZXh0cmFjdG9ycy90aWZmaW1hZ2luZ2V4dHJhY3RvcnMvc2NhbmltYWdldGlmZl91dGlscy5weQ==) | `87.87% <20.00%> (-12.13%)` | :arrow_down: |