-
Notifications
You must be signed in to change notification settings - Fork 6
/
White balance correction_1.0.ijm
64 lines (52 loc) · 1.62 KB
/
White balance correction_1.0.ijm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Original code by Vytas Bindokas; Oct 2006, Univ. of Chicago
// https://digital.bsd.uchicago.edu/docs/imagej_macros/_graybalancetoROI.txt
// This macro white balances RGB to a selected region (equal R,G,B =gray)
// draw a region prior to running the macro
// Code modified by Patrice Mascalchi, 2014, Univ. of Cambridge UK
// Ask for region to be drawn / Check region existence / check RGB at start / compaction of code (loop)
setTool(0);
waitForUser("Draw a region over background");
run("Set Measurements...", " mean redirect=None decimal=3");
if (selectionType==-1) exit("you must draw a region first");
ti = getTitle;
run("Select None");
//setBatchMode(true);
run("Duplicate...", "title=rgbstk-temp");
origBit = bitDepth;
if (bitDepth() != 24) exit("Active image is not RGB");
run("RGB Stack");
run("Restore Selection");
val = newArray(3);
for (s=1;s<=3;s++) {
setSlice(s);
run("Measure");
val[s-1] = getResult("Mean");
}
run("Select None");
run("16-bit");
run("32-bit");
Array.getStatistics(val, min, max, mean);
for (s=1; s<=3; s++) {
setSlice(s);
dR = val[s-1] - mean;
if (dR < 0) {
run("Add...", "slice value="+ abs(dR));
} else if (dR > 0) {
run("Subtract...", "slice value="+ abs(dR));
}
}
run("16-bit");
run("Convert Stack to RGB");
rename(ti + "-corrected");
//closeWin("Results");
closeWin("rgbstk-temp");
setBatchMode("exit and display");
run("Tile"); // Can be removed
// ------------------------------------------------------------------------------------------
// close any window without returning any error
function closeWin(name) {
if (isOpen(name)) {
selectWindow(name);
run("Close");
}
}