Bioformats doesn't create colour lookup tables for .CZI in MatLab

I recently started using Bioformats to evaluate my image stacks in Matlab.
It works like a charm for my data from the Leica setup (all .lif files) but somehow it doesn’t provide any lookup table for colour/intensity for the data obtained with a Zeiss setup (.czi). After finding some useful scripts ( and trying to get behind it I am still stuck and don’t know why it doesn’t work.
Thanks for your help!!!
Best, Anna

Hi Anna,

I am the one who created those scripts. Which version of bioformats are you using in Matlab?

Most likely this feature is just not supported by bioformats when reading CZI.

Are the LUTs created correctly when opening the CZI in Fiji with the latest BioFormats?

And maybe you can provide a small test CZI?


Hi Anna and Sebi,
depending on the file format the LUT color may be stored or not. In some formats (I believe the old Zeiss ZVI format) only emission and excitation wavelengths are stored. In this case, one needs to get the wavelength and convert it to a closest color.

Considering CZI format: I never had issues to obtain LUT color, to do that one needs to call getChannelColor function.

I briefly checked GetOMEData.m function and it seems that getChannelColor function is not used, instread the channels obtained with this code:

OMEData.Channels{c} = char(omeMeta.getChannelName(imageID, c-1));
OMEData.Dyes{c} = char(omeMeta.getChannelFluor(imageID, c-1));

To fix that, the code has to be extended with something like that:

for colCh=1:OMEData.SizeC
if isempty(omeMeta.getChannelColor(imageID, colCh-1)); continue; end
rgb(colCh, 1) = OMEData.getChannelColor(imageID, colCh-1).getRed();
rgb(colCh, 2) = OMEData.getChannelColor(imageID, colCh-1).getGreen();
rgb(colCh, 3) = OMEData.getChannelColor(imageID, colCh-1).getBlue();
lutColors = rgb/255; % scale between 0 and 1

Best regards,

Hi Sebi06,
thanks for the fast response!
If I open a image stack in Fiji with BioFormats I am able to split the channels (I don’t know if that is what you are asking?).
I am happy to provide a test CZI…I actually have a perfect one…we checked if a dye has any autofluorescence and have an “image stack” with one plane (two channels) somehow it works with that one. I just tried to change the color of one channel in Zen…saved it again (check.czi) and it doesn’t work anymore (even the file size changed!)
Pls find two examples in the dropbox folder, 200227_H3_200218.czi is the one where it works and the other ones don’t.

If you open them with data=bfopen(‘200227_H3_200218.czi’) you will see that data{1,3} has lookup tables for both channels but the other ones don’t provide that information.
Thanks a lot for your help!

Best, Anna

Hi Ilya,
Thanks for your help!!!
I tried to add what you suggested but I couldn’t get anywhere…my coding skills might just be too limited or there are additional issues with my image stacks.
As you can see above in my answer to Sebi06 it seems to be an issue created by the ZEN software…opened a file which worked perfectly in the Matlab framework, changed the colour of the channel, saved it, opened it in Matlab again and it didn’t provide me with a LUT anymore.
Maybe this helps in any way?
PLs let me know if you think there is some information missing and I will try to come up with it asap!
Best, Anna

Hi Anna,
your replies are quite confusing.
I can open 200227_H3_200218.czi

and check.czi

file: 191119_No_Clearing_DAPI_x20_SHG_2_14_24_56_H1.czi I was not able to open.

if you use bfopen function you can get LUT as:

for colCh = 1:2
    rgb(colCh, 1) = data{4}.getChannelColor(0, colCh-1).getRed();
    rgb(colCh, 2) = data{4}.getChannelColor(0, colCh-1).getGreen();
    rgb(colCh, 3) = data{4}.getChannelColor(0, colCh-1).getBlue();

Hi Ilya,
thank you very much.
Sorry for not being more clear!
This is very surprising…on my system all three open but no lookup table for:
but I get them for:

I added a *.m file to the dropbox folder for a test plot…if you download the folder as it is and test it in Matlab I guess it is more clear what I am trying to say.
For the 200227_H3_200218.czi file I do get the lookup table if I use data=bfopen(‘200227_H3_200218.czi’);
but for the others I don’t.
Thank you very much for your help!
Best, Anna

Hi Anna,
would this work for you:

%% test
% download bioformats to get bfopen()
% select filename (add path
DataPath = fullfile(pwd,’’);
CziList = dir([DataPath, ‘*.czi’]);

for m = 1:length(CziList)

%filename = '200227_H3_200218.czi';
filename = CziList(m).name;
data = bfopen(filename);
s = 1;    %series/tile
z =  1;    %plane
p =  length(data{1,1})/2;  %total_#_plane

series19 = data{s,1};

series19_plane1_c1 = series19{z,1};
series19_label1_c1 = series19{z,2};

series19_plane1_c2 = series19{z+1,1};
series19_label1_c2 = series19{z+1,2};

%series19_colorMaps = data{s, 3};
%c1_colormap = series19_colorMaps{s,z};
%c2_colormap = series19_colorMaps{s,z+1};

vec = 0:1/255:1;
cmap = cell([2, 1]);
for colCh = 1:2
    rgb(1) = data{4}.getChannelColor(0, colCh-1).getRed()/255;
    rgb(2) = data{4}.getChannelColor(0, colCh-1).getGreen()/255;
    rgb(3) = data{4}.getChannelColor(0, colCh-1).getBlue()/255;
    cmap{colCh} = rgb.*vec';

s1 = subplot(2,1,1);
img_1 = squeeze(series19_plane1_c1);
axis equal
axis tight

s2 = subplot(2,1,2);
img_2 = squeeze(series19_plane1_c2);
axis equal
axis tight


you need to generate an own lut table, which is basically an equally spaced matrix (3x256) from 0 to 1 for each red, green and blue channels.

Hi Anna,

I checked you CZI files in ZEN and then I opened them using BioFormtas in Fiji to check if the meatdata are read correctly. And for me it looks pefect. All metadata are red correctly incl. the LUTs and the image is dispayed correctly. So I am not quite sure what your actual issues is.

Obviously displaying this 2-color Z-Stack in MATLAB incl. the correct LUTs is a different topic, but this has nothing to do with the CZI file itself. Using BioFormats from MATLAB to read this CZI will give the the correct pixeldata and metainformation. The choice of your colormaps in MATLAB is of course still up to you.

Does this makes sense ot did I misunderstood you?

Hi Sebi06,

It seems like we are not on the same page yet…thank you so much for bearing with me!

I can open all my images as well (in Fiji and Matlab) the only issue is that the bfopen() function in matlab isn’t able to read/extract the lookup tables correctly for most of my *.czi files. I don’t know if you use Matlab but if I run the *.m file I uploaded into the dropbox folder it works for the 200227_H3_200218 file but for the other ones it doesn’t. What I mean by it doesn’t work is that I can’t extract the color lookup table for the others.
Works perfectly!
Doesn’t work even though it is the same image saved with Zen Software

I seriously don’t know what causes this “information loss” or better say the information not being read correctly.
This might seem like it is not worth it but I do depend on the lookup table being stored/read because I need the values for a filter. And it doesn’t make sense to me, that bfopen() seems to be unable to do this for all but two of my *.czi files especially that it happens if I basically only change the name of the file in ZEN and resave it.
Thank you very much for your help!

Best, Anna

Hi Sebi06,

Sorry to bother you again with this issue!
After looking into it with a fresh mind today I am pretty sure it is an issue which occurs due to the ZEN software. I actually should have realised this earlier because if you look at the file size in the dropbox folder of the two identical image stacks (if you don’t count the name) there is some KBs missing as well. Have you ever heard of such an issue? I am still very confused how this can happen so in case you have an explanation I would be very grateful if you could help me!

Thank you for your help so far!

Best, Anna

Hi Anna,

I am sorry that you think this is related to ZEN, but I have I hard time to understand why urn has anything to do with the way the image is displayed in Matlab.
Whenever one modifies a CZI in ZEN incl. Applying LUTs the filesize will change because the metadata will be altered.
And when opening those files in Fiji using Bioformats everything looks fine.
So I am still not sure what the actual problem is.

Hi Sebi06,

I had the same thought and double checked everything to be sure it is ZEN and not something in Matlab (+Bioformats).
I took two original image stacks and opened it in ZEN blue edition and saved it as (blue_xy.czi) and opened it in ZEN black edition and saved it (black_xy.czi). As you can see in the screenshot bfopen() is able to read the “colormap” info (data{s,3}) for the black_xy.czi files but not for the blue_xy.czi.

I still don’t have a clue why this is but to make things even “weirder” if I open the blue_xy.czi file in ZEN black edition and save it again (e.g. fork_45.czi) it all works again!
So for now my solution is to open all acquired stacks in ZEN black edition and save them and then take it from there.
Thank you for your help and sorry not being able to explain the issue in a clearer way! Pls let me know if there is any additional information in case you want to look further into this.
Best, Anna

I still think this is because of Bioformats and small differences between ZEN Blue and the much older ZEN black.

Hi Sebi06,

As I said I don’t know what causes it but somehow the bfopen() function is able to read the information when I save it with the ZEN black edition. I am not trying to blame anything on Zeiss/ZEN this is just what I experienced and maybe someone else will have the same issue and this could fix it that’s why I thought it is a good addition to the topic.

Best, Anna