Description
Hello,
Many thanks for MEXlibCZI!!!
It solves a big problem for me by greatly speeding up the reading of CZI files into matlab.
However, I recently came across a problem that does not seem easy to solve.
I have a dataset consisting of linescan confocal images. Essentially one line of an image is scanned repeatedly over time.
In these files, each subblock contains several lines. This is clear from reading the subblock metadata (for example, MEXlibCZI('GetMetadataFromSubBlock', h, sb) on the first subblock in the file returns XML with 8 different time points).
But when using
sb = MEXlibCZI('GetSubBlock', h, i - 1);
img = MEXlibCZI('GetBitmapFromSubBlock', h, sb);
MEXlibCZI('ReleaseSubBlock', h, sb);
to iterate over the 1286 subblocks contained in the file, it only returns the first line in each subblock.
Zen reads the image correctly, displaying all 14400 lines that the file contains. But MEXlibCZI returns a much smaller subset.
Is there a workaround that makes it possible to read all of the lines in the file?
I'm uploading a zip file containing an example file with linescan data.
Many thanks!
Anders
Activity
ptahmose commentedon Sep 23, 2026
Hi Anders,
thanks for providing the example file. I had a look at it, and the issue appears to be related to the way the image data is represented in this particular CZI file.
The file uses a somewhat uncommon — and arguably controversial — organization of the image data. More precisely, the structure of the CZI is not quite what libCZI expects and currently handles: a single subblock appears to contain data corresponding to multiple time points, whereas libCZI generally treats a subblock as a single logical image tile with one coordinate in each dimension.
So, as far as I can tell, this is not primarily a problem with the MATLAB wrapper or with the iteration over the subblocks. The information is present in the file, but libCZI does not currently expose the additional lines/time points contained within such a subblock in the way one might expect.
I'll have a closer look and see what can reasonably be done to support this case. I can't promise a proper solution at this point, but there may be a pragmatic workaround — even if it ends up being somewhat makeshift.
ptahmose commentedon Sep 29, 2026
Hi Anders,
following up on this: I have put together a rough prototype that adds a workaround in libCZI and exposes it through MEXlibCZI. I added an optional third argument,
OpenOptions, to theOpenMEX function. It accepts a string of semicolon-separated key=value pairs. In the example below, these options enable the workaround.The idea is to reinterpret the time dimension (T) as the image’s vertical dimension (Y). This makes the successive scan lines within each subblock accessible as bitmap rows, with the vertical axis representing time rather than a spatial Y coordinate.
The prototype is available on the jbl/XT branch. You can find the corresponding build here: GitHub Actions build.
For your example file:
The region comes directly from the bounding box returned by GetInfo. For your file, this is [109821 0 361 14400]: an X offset of 109821, a Y offset of 0, a width of 361 pixels, and all 14400 scan lines along the vertical axis. The composite reader assembles the subblocks into that region, so you do not need to iterate over them manually.
Please consider this a rough prototype—a pragmatic workaround for this particular data layout that still needs further refinement and testing.
Would you be willing to try it and compare the resulting image with what ZEN displays? It would be helpful to confirm that the lines and their ordering match your expectations.
andfridb commentedon Oct 1, 2026
Hello
I can confirm that this works fine, and it returns the exact same result as I'm getting when reading the file with Zen.
The workaround also seems to be faster than reading individual subblocks one by one, and it works fine for spot scanning data which are notoriously slow to read.
So big thanks for the update!
Anders
ptahmose commentedon Oct 1, 2026
Great, that's good news.
OK, so then I'll
I don't expect this to happen in the next days, so in the meantime I hope you can go with the prototype. Please let me know if you encounter any issues.
ptahmose commentedon Oct 19, 2026
A new version has been prepared including those changes -> https://github.com/ptahmose/MEXlibCZI/releases/tag/v0.4.0-alpha
The changes to libCZI have been upstreamed -> ZEISS/libczi#181
Note that the syntax for the open-options has changed (compared to the prototype). For your case, the option string now reads
dimensionSwapWorkaround=XtSubblocks.