8000 Reconstructing image order of exported sub-sets · Issue #18 · ptahmose/MEXlibCZI · GitHub
[go: up one dir, main page]

Skip to content

Reconstructing image order of exported sub-sets #18

Closed

Description

@Gebhard-Stopper

Hello there!

I recently exportet image sub-sets from ZEN and noticed that the original image order is not retained. Probably due to the multi-threaded export.
To reconstruct the correct image order, I wrote a small function that loops over all subblocks in the exported file and reads the SubBlockinfo ( info = MEXlibCZI('GetInfoFromSubBlock', hFile, SID); ). Then, I use info.Coordinate to determine the correct position of each image.
This works, but can be quite slow, especially if the CZI files are on a server.

It seems like ZEN itself does is on the fly, or better in some way. Scrolling through the exported fies in ZEN does not show any noticable lag.

So my question is: Is there a better / faster / more efficient way to do this?

Activity

  1. ptahmose commented on Oct 17, 2026

    @ptahmose
    Owner

    Hi,

    I'm not entirely sure I understand what you're trying to achieve here.

    When you say that the "original image order is not retained", what exactly do you mean by "order"? Are you referring to the order in which subblocks are enumerated in the CZI file, or to the order of images along a particular dimension (e.g., Z, T, or C)?

    In general, the order in which subblocks are stored in a CZI file is not guaranteed to correspond to any particular logical ordering. The coordinates associated with each subblock are what determine its position in the multidimensional dataset.

    The straightforward approach would be to use GetSubBlock to obtain a handle to the desired subblock, then GetBitmapFromSubBlock to retrieve the bitmap, and finally ReleaseSubBlock to release the handle.

    However, before suggesting a more efficient approach, I'd like to better understand what you're doing. In particular, why do you need to iterate over all subblocks and reconstruct their order in the first place?

    Ideally, it would be helpful if you could provide a complete, reproducible example, including a sample CZI file and the code you're using. That would make it much easier for me to understand the problem and investigate possible solutions.

  2. Gebhard-Stopper commented on Oct 19, 2026

    @Gebhard-Stopper
    Author

    Hi,

    Thanks for the reply, and apologies for not expressing clearly what I meant.

    What I meant by image order ist the dimensional order. In our case, in the original CZI file this corresponds to the order in which the images are recorded, [X,Y,C,Z,S,T]. And, after subset export this order is not maintained.

    Yes, when I retrieve images, I call GetSubBlock, GetBitmapFromSubBlock and ReleaseSubBlock.

    What I've done is, separate retrieving metadata from retrieving images. So, what I do in a separate step is: GetSubBlock, GetInfoFromSubBlock, GetMetadataFromSubBlock and ReleaseSubBlock. With this, I can restore the dimensional ordering I want and get other, per sub block info I need.

    Is there another way to do this? Is this even the correct way?

    At the moment, I load one dataset, not an entire file, (e.g. a single well) with all images and metadata. What I'm aiming at is to load only specific sub block bitmaps on demand, and I was wondering if there is another way to get the sub block Metadata and Info, since (from my perspective) this seems what ZEN is doing.

  3. ptahmose commented on Oct 19, 2026

    @ptahmose
    Owner

    Thanks for your message.

    Hmmm, I am still not completely sure I understand what you are trying to achieve, but - I get the idea what you are looking for is something like the functionality ISubBlockRepository::EnumerateSubBlocks or ISubBlockRepository::EnumSubset (c.f. here). This enables to find the "subblocks for a given plane", which you then can read and process. Note that this enumeration does not incur any file-operation.

    So, the operation would then look something like this:

    • get the "statistics" (GetInfo)
    • then, loop over the dimensions/scenes (as reported by the statistics)
    • use EnumerateSubBlocks (not currently available in MEXlibCZI!) to find the subblocks for the given coordinate (C,Z,T,S...), then operate on the subblocks

    Alternatively - if the order (in which the subblocks are processed) is not relevant, then you could also simply enumerate all subblocks (by just incrementing the index), then GetInfoFromSubBlock gives you the coordinate. This gives essentially the same result, just the order is different.

    Well - if this makes sense to you, then adding such a function "EnumSubBlocks" to MEXlibCZI would be possible of course.

    It should also be possible to implement the desired functionality with C++, .NET (https://github.com/ZEISS/LibCZI_NET) or Python (https://github.com/ZEISS/pylibczirw/) if this is an option for you - as those should have the required functionality available.

    Please let me know if you think such an addition to MEXlibCZI (i.e. something like EnumSubBlocks) would be helpful for you.

  4. Gebhard-Stopper commented on Oct 19, 2026

    @Gebhard-Stopper
    Author

    Thank you for your answer!

    I think, EnumSubset could be quite helpful and might be worth adding to MEXlibCZI.
    In my case it would be important to get the corresponding subblock ID alongside the SubblockInfo, but as far as I understand, EnumSubset can do that.

    Unfortunately, C++ or python are currently no option for me - the MEXlibCZI implementation would thus be really great.

  5. ptahmose commented on Oct 20, 2026

    @ptahmose
    Owner

    I drafted a prototype - maybe you want to check if this fits your needs. Binaries would be available here -> https://github.com/ptahmose/MEXlibCZI/actions/runs/39402208067

  6. Gebhard-Stopper commented on Oct 20, 2026

    @Gebhard-Stopper
    Author

    Wow, that was fast! Thank you!

    I did a quick test in MATLAB 2026b with a range of coordinates and it worked like a charm!

    I don't wan to push it too far, but is there a similar function to retrieve the AcquisitionTime of subblocks?

  7. ptahmose commented on Oct 21, 2026

    @ptahmose
    Owner

    I made some more tweaks to the new QuerySubBlockDirectory function, and completed the PR.

    is there a similar function to retrieve the AcquisitionTime of subblocks?

    AcquisitionTime is not stored in the subblock directory, so QuerySubBlockDirectory cannot return it. Retrieving it requires reading the individual subblock and inspecting its metadata XML, which you can access through GetMetadataFromSubBlock.

    The relevant concept here is the T dimension: a subblock’s T coordinate identifies a time-point index, rather than a timestamp itself. The timestamp associated with that index is recorded in the document's metadata XML (accessible with GetMetadataXml). Multiple subblocks can belong to the same T index, so there is not necessarily a separate time point for every subblock.

  8. Gebhard-Stopper commented on Oct 21, 2026

    @Gebhard-Stopper
    Author

    Thank you so much, I already integrated QuerySubBlockDirectory into my file-reader.
    This simplified quite a bit of my code.

    What you describe is basically what I do to get AcquisitionTime. I was just hoping there was a similar mechanism.

    Thanks again for implementing this so quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0