You signed in with another tab or window. Reload
8000
to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reconstructing image order of exported sub-sets #18
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?
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.
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.
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:
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.
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.
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.
Activity
ptahmose commentedon Oct 17, 2026
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
GetSubBlockto obtain a handle to the desired subblock, thenGetBitmapFromSubBlockto retrieve the bitmap, and finallyReleaseSubBlockto 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.
Gebhard-Stopper commentedon Oct 19, 2026
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,GetBitmapFromSubBlockandReleaseSubBlock.What I've done is, separate retrieving metadata from retrieving images. So, what I do in a separate step is:
GetSubBlock,GetInfoFromSubBlock,GetMetadataFromSubBlockandReleaseSubBlock. 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.
ptahmose commentedon Oct 19, 2026
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:
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
GetInfoFromSubBlockgives 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.Gebhard-Stopper commentedon Oct 19, 2026
Thank you for your answer!
I think,
EnumSubsetcould 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,
EnumSubsetcan do that.Unfortunately, C++ or python are currently no option for me - the MEXlibCZI implementation would thus be really great.
ptahmose commentedon Oct 20, 2026
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
Gebhard-Stopper commentedon Oct 20, 2026
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
AcquisitionTimeof subblocks?ptahmose commentedon Oct 21, 2026
I made some more tweaks to the new
QuerySubBlockDirectoryfunction, and completed the PR.AcquisitionTime is not stored in the subblock directory, so
QuerySubBlockDirectorycannot return it. Retrieving it requires reading the individual subblock and inspecting its metadata XML, which you can access throughGetMetadataFromSubBlock.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.Gebhard-Stopper commentedon Oct 21, 2026
Thank you so much, I already integrated
QuerySubBlockDirectoryinto 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!