Normalizing intensity for each channel in a stack

Hi everyone,

Can someone advise on how I can normalize the intensity of each channel to the brightest pixel of the corresponding channel (within a stack)? I wrote the following function and it seems that when I perform the division on the brightest pixel (of the corresponding channel), the division is applied to all 3 channels. How do I ensure that the normalization is specific to the corresponding channel?

function Norm2BrightestInt(){
	Stack.getDimensions(width, height, channels, slices, frames);
	if(channels>1){
		for(i=0; i<channels; i++){
			Stack.setChannel(i+1);
			getStatistics(area,mean,min,max);
			print(max);
			//run("Select All");
			run("Divide...", "value=max");
		}
	}
	else {
			getStatistics(area,mean,min,max);
			run("Select All");
			run("Divide...", "value=&max");
	}
}

Thanks in advance.
WJ

@WJ89

Have you thought about perhaps splitting the channels first? Then selecting each window as you go - applying your normalization - and then at the end, you can merge the channels once again. Not sure this is the best fix … but might be a decent workaround for now.

eta

Hi etarena,

I’m sorry about the latent reply. That’s actually what I’ve been doing. Just wondering if there’s a neater to get around this problem as it makes the code bulky.

Thanks.
WJ