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

Add function to extract ROIs metadata from ScanImage tiff #272

Merged
merged 9 commits into from
Jan 24, 2024

Conversation

alessandratrapani
Copy link
Collaborator

@alessandratrapani alessandratrapani commented Jan 22, 2024

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 (#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

Copy link
Member

@pauladkisson pauladkisson left a comment

Choose a reason for hiding this comment

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

Thank you for catching this. It looks like there's a whole swath of metadata stored in a json-style string that we haven't been extracting.

However, I would prefer if this were integrated into the existing extract_extra_metadata function. That way the metadata function would return all the metadata in the 'system_metadata_string' AND the 'extra_metadata_string' (as you called them). Then you can add a section to grab the ROI groups in the parse_metadata function.

Copy link
Member

@pauladkisson pauladkisson left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for implementing the changes.

Copy link

codecov bot commented Jan 24, 2024

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.

❗ 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

@@            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 Coverage Δ
unittests 79.00% <20.00%> (-0.20%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...ctors/tiffimagingextractors/scanimagetiff_utils.py 87.87% <20.00%> (-12.13%) ⬇️

@alessandratrapani alessandratrapani merged commit 1a136a5 into main Jan 24, 2024
15 checks passed
@alessandratrapani alessandratrapani deleted the extract_roi_metadata_from_scanimage branch January 24, 2024 20:26
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.

2 participants