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

Tile compositing not working #244

Closed
arjunrajlab opened this issue Jul 25, 2022 · 6 comments · Fixed by #331
Closed

Tile compositing not working #244

arjunrajlab opened this issue Jul 25, 2022 · 6 comments · Fixed by #331
Assignees
Labels
bug Something isn't working enhancement New feature or request
Milestone

Comments

@arjunrajlab
Copy link
Collaborator

@manthey not sure if the file reader was set to do this, but it seems that currently, the software doesn't do compositing. For instance, here is an ND2 file with a bunch of tiles, but the software doesn't composite it together into a big stitched image. Is that a feature that is easy to enable?

https://www.dropbox.com/sh/aagt5bf24t0o7zm/AACPG12_mndS0pqMXgqG4aada?dl=0

@arjunrajlab arjunrajlab added bug Something isn't working enhancement New feature or request labels Jul 25, 2022
@arjunrajlab arjunrajlab added this to the Alpha-Version milestone Jul 25, 2022
@finetjul
Copy link
Collaborator

On 2022/07/29: @manthey does not reproduce

@zjniu can you reproduce and send a screenshot

@manthey
Copy link
Collaborator

manthey commented Aug 12, 2022

This will use the internal metadata from the nd2 files that contains the location for each XY tile. We then can generate the multi-source yaml file with the appropriate coordinates to composite it. I'll make a sample to demonstrate.

@manthey
Copy link
Collaborator

manthey commented Nov 18, 2022

This need a small tweak to to the multi source to properly composite tiles if the first one wasn't at the origin (girder/large_image#993).

This can work for any file where we have coordinates for the XY frames. This is probably only for nd2 files unless we examine and determine the location of such data (OME tiffs also have it, at least).

The process that needs to be done (in python pesudo code):

ts = large_image.open(<nd2 path>)
# We need the scale and frame list from the metadata
metadata = ts.getMetadata()
# We need the xy positions from the internal metadata
internal = ts.getInternalMetadata()
# Extract the x, y coordinates in pixels.  If we throw an exception here, then we can't do composite
# There will be one set of coordinates for each unique combination of z, t, xy (not c)
coordinates = [[
    f['position']['stagePositionUm'][0] / metadata['mm_x'] / 1000, 
    f['position']['stagePositionUm'][1] / metadata['mm_y'] / 1000
] for f in internal['nd2_frame_metadata']]
# Find the min values
minc = [min(xy[0] for cc in coordinates), min(xy[1] for xy in coordinates)]
# Convert to integer pixels where the left and top are 0 and 0
coordinates = [[int(xy[0] - minc[0]), int(xy[1] - minc[1])] for cc in coordinates]
# General a yaml file (this assumes number of frames and a bunch of other stuff -- it was taken from a 2 channel example)
multi_source = {
    'channels': ['GFP', 'DAPI'],  # or whatever the channels are
    'sources': [{
        'path': <nd2 path>, 
        'c': 0,   # We keep the existing channel stack
        # We probable need to specify t and z appropriately here
        'frames': [xy * 2, xy * 2 + 1],  # list of frames with this exact z, t, xy (i.e., all the channels for this frame)
        'xySet': 0,  # we are discarding the xy information
        'position': {'x': xy[0], 'y': xy[1]}
    } for xy in coordinates]
}
# Save a yaml file
open('sample.yaml', 'w').write(yaml.safe_dump(multi_source))

@manthey
Copy link
Collaborator

manthey commented Nov 18, 2022

I think the UI will be added in src/views/dataset/MultiSourceConfiguration.vue. 20210723_155544_798__Plate20210723_STR_gfp_Well03_ChannelGFP,DAPI_Seq0000.nd2 is a good example.

@arjunrajlab
Copy link
Collaborator Author

@bruyeret @manthey Ping

@arjunrajlab
Copy link
Collaborator Author

Need to apply a matrix transform FYI.

bruyeret added a commit that referenced this issue Dec 6, 2022
Read position metadata of tiles from nd2 file

Closes #244
@arjunrajlab arjunrajlab moved this to Done in Alpha Release May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants