Skip to content

Instantly share code, notes, and snippets.

@mutterer
Created June 5, 2019 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mutterer/819909745278f2160d820d2d80bf7a42 to your computer and use it in GitHub Desktop.
Save mutterer/819909745278f2160d820d2d80bf7a42 to your computer and use it in GitHub Desktop.
white_balance_from_grey_area corrects an RGB image white balance using a reference ROI
setBatchMode(1);
t=getTitle();
getBoundingRect(x, y, width, height);
run("Select None");
run("Duplicate..." , "title=ori duplicate");
makeRectangle(x, y, width, height);
run("RGB Stack");
run("32-bit");
id=getImageID;
run("Duplicate..." , "title=temp duplicate");
run("Gaussian Blur...", "radius=1 stack");
m = newArray(3);
for (c=0;c<3;c++) {
setSlice(c+1);
getRawStatistics(nPixels, mean, min, max, std, histogram);
m[c]=mean;
}
Array.getStatistics(m, min, max, mean, stdDev);
selectImage(id);
run("Select None");
for (c=0;c<3;c++) {
setSlice(c+1);
f = max/m[c];
run("Multiply...", "value=&f");
}
run("8-bit");
run("RGB Color");
rename ("WB_"+t);
setBatchMode(0);
@darcyabjones
Copy link

Hi there,
I'm adapting an ImageJ pipeline that my colleagues regularly run to some python scripts which can be run on HPC a bit more easily.
They use your macro (which I think they found from here: https://forum.image.sc/t/normalization-of-true-white-to-compare-pigment-across-images/26322/4) to remove a colour imbalance caused by plant grow lights.

I was wondering why you use getRawStatistics in the per channel/slice loop but getStatistics outside of it.
It's a bit difficult to see what exactly the calibration does in getStatistics from the documentation, and this seems to just be finding the overall maximum value in the array.
Is it necessary?

Thanks and all the best :)

Darcy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment