Equalize image stack - CLIJ2_multiplyImageStackWithScalars

Yes that’s right!

My starting point is a stack of RGB images, imported as a time sequence of .bmp images.
I’ll have to discover if the Stack.setChannel command is valid for that starting point. But it will be the first thing that I try. In the end I could always get individual stacks of the channels with Image/Color/Split channels.

I understand that after run("Merge Channels… I have my original RGB sequence back, but now processed. That would be great. I’ll let you know when I have some results.

In the mean time I learned the following:

  • All the things that we have discussed before was on images AFTER segmentation/labeling. And these are always 8 bits. So can be handled by CLIJ2 right away.

  • The discussion in this thread is on pre-processing the input images, which are 32bit RGB. So we need to split those and handle individual channels in CLIJ.

  • Your remarks

…have triggered me to think about separating channels or conversion to a single gray scale before I do segmentation with the WEKA tool. I could then introduce color information again after segmentation. It would mean a major change of my app, making all efforts on combination of classifications or probability maps obsolete, but could give additional analysis insight to a user.

Hi @haesleinhuepf , I combined the various snippets of code to the following working (!) code:

[EDIT] For the record :slight_smile: Although the code worked some times, it also regularly fails… It works fine when I convert the stack that was imported as a sequence of RGB images from .BMP files to a hyperstack with 3 channels.

// Apply time/slice  dependent intensity correction to stack of RGB images
// With the proper info in ref_Value / pre_Factor this can be used to equalize the average intensity in a stack or (more useful) a reference ROI in a stack
   
   // run("Close All");
    run("CLIJ2 Macro Extensions", "cl_device=");
	Ext.CLIJ2_clear();

	//fill array pre_Factor with dummy values for testing 
    ref_Value = newArray(35);
	pre_Factor = newArray(ref_Value.length);

	for (ii = 0; ii < ref_Value.length; ii++){
		pre_Factor[ii] = ii/35; //normally depends on ref_Value					//set factor to zero for clearest result				//target_Value/ref_Value[ii];
	};
// [EDIT] convert stack of RGB images to hyperstack with 3 channels
run("Stack to Hyperstack...", "order=xyctz channels=3 slices=1 frames=35 display=Color convert");
	
        image = getTitle();
	Stack.setChannel(1);
	Ext.CLIJ2_pushCurrentZStack(image);
	
	//result1 = process(image);
	//result1 = image; //process is: do nothing
	Ext.CLIJ2_multiplyImageStackWithScalars(image, equalizedStack1, pre_Factor);

	

	Stack.setChannel(2);
	Ext.CLIJ2_pushCurrentZStack(image);
	//result2 = process(image);
	//result2 = image;  //process is: do nothing
	Ext.CLIJ2_multiplyImageStackWithScalars(image, equalizedStack2, pre_Factor);
	
	Stack.setChannel(3);
	Ext.CLIJ2_pushCurrentZStack(image);
	//result3 = process(image);
	//result3 = image;  //process is: do nothing
	Ext.CLIJ2_multiplyImageStackWithScalars(image, equalizedStack3, pre_Factor);

	Ext.CLIJ2_pull(equalizedStack1);
	Ext.CLIJ2_pull(equalizedStack2);
	Ext.CLIJ2_pull(equalizedStack3);

	run("Merge Channels...", "c1=" + equalizedStack1 + " c2=" + equalizedStack2 + " c3=" + equalizedStack3 + " create");

I just had to replace process(image) with the stack-array multiplication trick of earlier posts.

Thanks
Fred

1 Like