CLIJ copy metadata from input image to output image

Hi there, I was wondering if there is any way to copy the metadata (or at least x,y,z voxel scale information) from CLIJ input images to CLIJ output images?

For example 1 voxel (x,y,z) in my input images represent (0.6μm,0.6μm,0.8μm). I would like to keep that scale information when I use either CLIJ or clEsperanto to manipulate those images, is there any way to do this?



1 Like

Hi @Matt_Hunt ,

yes, we introduced pushMetaData and popMetaData for exactly that.

Let me know if it works for you!


Thanks for the response Robert!!

I have tried playing with pushMetaData and popMetaData and I’m having some trouble.

I assumed that pushMetaData() would push the metadata from open stack and popMetaData would populate the stored MetaData to the next image that is pulled from GPU? or something along those lines, but I’ve tried every iteration and haven’t gotten it to work.

I am wondering if its possible to make CLIJx_cpMetadata(image_source,image_PopulateMetadata, image_destination) or something along those lines that would just copy the metadata from an input image and apply it to an existing image so that when its pulled from GPU it would contain the original images metadata?

Thanks as always!


1 Like

Ah I see, the stack explanation is a bit misleading as it’s not referring to an image stack. Maybe this macro makes more clear how this is supposed to work:

run("CLIJ2 Macro Extensions", "cl_device=[Intel(R) UHD Graphics 620]");
run("T1 Head (16-bits)");

getPixelSize(unit, pixelWidth, pixelHeight);
print("Original pixel size:", pixelWidth);

// store meta data

// process image on GPU
image1 = getTitle();
Ext.CLIJ2_gaussianBlur3D(image1, image2, 2, 2, 2);

getPixelSize(unit, pixelWidth, pixelHeight);
print("Pixel size after processing:", pixelWidth);

// restore meta data

getPixelSize(unit, pixelWidth, pixelHeight);
print("Pixel size after restoring meta data:", pixelWidth);


I like the idea and put it on the wishlist. Btw, images in clij do not have any meta data regarding pixel size. This is a feature of ImageJ. Also the two push/popMetaData methods do not do anything with images on the GPU. You could actually use them with any other image processing library to store/restore meta data.

Let me know if the macro snippet helped!


1 Like

I love the push/popMetaData functions!
I was cobbling something to read pixel size, store it, then use set scale to restore it, etc. Happened upon this thread when browsing and tada the solution!
Works great, but this approach fails if I don’t have a stack open :frowning:
Now typically I am processing stacks, but not always…
Can we perhaps provide an image title/ID for pushMetadata?
popMetadata just applies the Metadata to the current object, so that shouldn’t need any changes…

1 Like

Sounds like a great idea! In the meantime, you can call selectWindow(title); just before pushing or popping meta data. Does that solve the task for you @psobolewskiPhD ?

1 Like

It works perfectly, but I may have failed in my report above.
I think maybe my issue was that I had some images lacking meta data (from CLIJ before the push/pop trick) :frowning:
…and not that I had no stacks open (which was also the case).

Images in clij do not have any meta data regarding pixel size.

Yup, that’s how I got down this rabbit hole :slight_smile:
Maybe I had something un-closed. I will monitor and see if I can reproduce my initial issue.

1 Like