-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathColor Coding Frames.ijm
78 lines (70 loc) · 2.68 KB
/
Color Coding Frames.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/** ===============================================================================
* Copyright (C) 2020 Jan Niklas Hansen
* *
* This macro is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation (http://www.gnu.org/licenses/gpl.txt )
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
*
* For any questions please feel free to contact me ([email protected]).
* =============================================================================== */
imgID = getImageID();
selectImage(imgID);
run("8-bit");
Stack.getDimensions(ww, hh, channels, slices, frames);
newImage("temp", "8-bit White", ww, hh, 1);
tempID = getImageID();
run("mpl-plasma"); //Replace "mpl-plasma" LUT to any LUT you like (e.g., "Spectrum", See all available LUTs and their names in your ImageJ at Image > Color > Display LUTs)
getLut(rA, gA, bA);
nrA = newArray(256);
ngA = newArray(256);
nbA = newArray(256);
selectImage(imgID);
run("Duplicate...", "duplicate");
run("RGB Color");
copyID = getImageID();
selectImage(copyID);
run("Stack to Hyperstack...", "order=xyczt(default) channels=1 slices="
+ slices + " frames=" + frames + " display=Color");
if(frames == 1){
IJ.log("Your image contains only one frame and thus can't be processed.");
IJ.log("Note: Eventually in your image frames and slices are incorrectly defined.");
IJ.log("Check this at Image > Hyperstacks > Reorder Hyperstack.");
IJ.log("If you have many slices that should be frames, change slices and frames here and run macro again.");
exit("Color Coding obsolete. Contains only one frame (more details in LOG)");
}
for (i = 0; i < frames; i++) {
colorscale = floor((256 / frames) * i);
for (j = 0; j < 256; j++) {
intensityfactor = j / 255;
nrA[j] = round(rA[colorscale] * intensityfactor);
ngA[j] = round(gA[colorscale] * intensityfactor);
nbA[j] = round(bA[colorscale] * intensityfactor);
}
for (j = 0; j < slices; j++) {
selectImage(imgID);
Stack.setPosition(1, j + 1, i + 1);
run("Select All");
run("Copy");
selectImage(tempID);
run("Paste");
setLut(nrA, ngA, nbA);
run("RGB Color");
run("Select All");
run("Copy");
run("8-bit");
selectImage(copyID);
Stack.setPosition(1, j + 1, i + 1);
run("Select All");
run("Paste");
}
}
selectImage(copyID);