Skip to content

Instantly share code, notes, and snippets.

@lgelman
Last active August 29, 2015 14:11
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 lgelman/edf042e8712afa9350ba to your computer and use it in GitHub Desktop.
Save lgelman/edf042e8712afa9350ba to your computer and use it in GitHub Desktop.
Shading Correction
//
// *** Start: White balance ***
//
name=getTitle();
run("Split Channels");
MeanColor=newArray(3);
maxi = 0;
for (u=1; u<4; u++) {
selectWindow("C"+u+"-"+name);
// Type of region, dimensions and position can be changed.
// A region in the backgroung (no object) should be choosen.
makeRectangle(100,100,100,100);
// The user can be prompted to draw a region at that stage. Remove the double slash in the next line.
// waitForUser("Please draw a region in the background");
getStatistics(area, mean);
MeanColor[u-1] = mean;
if (mean>=maxi) maxi = mean;
}
for (u=1; u<4; u++) {
selectWindow("C"+u+"-"+name);
run("Select None");
run("Multiply...", "value="+maxi/MeanColor[u-1]);
}
run("Merge Channels...", "c1=C1-"+name+" c2=C2-"+name+" c3=C3-"+name+" create");
run("RGB Color");
selectWindow(name); close();
// *** End: While Balance ***
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment