Adjusting brightness/contrast based on mean and sd of histogram

Hi, I am looking to adjust all of my 4 channel images based on the original mean and sd of each channel. As of now, I have been taking every image, making the histogram for each channel and recording the mean and sd. Then I calculate mean +2*sd, and take that value and put it into the min. for the brightness contrast adjustment. I feel like there must be a way to make this automated within a macro but I am not sure how.

Does anyone know?
Thanks in advance.

Hi @Nikita_Sturrock,

the following macro should do the job for composite images (not taking time or volume into account).

run("Select None");
getDimensions(w, h, c, s, f);
for(ch=1; ch<=c; ch++) {
	getStatistics(area, mean, min, max, std);
	setMinAndMax(mean+2*std, max);

hope this gets you started

1 Like