-
Notifications
You must be signed in to change notification settings - Fork 2
/
Image_Annotation.ijm
61 lines (57 loc) · 1.83 KB
/
Image_Annotation.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
// Copyright 2018-2023 Zhou XU
//
// This file is part of ImageJ plugin EM-tool.
//
// EM-tool 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, either version 3 of the License, or
// (at your option) any later version.
//
// EM-tool 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 EM-tool. If not, see <http://www.gnu.org/licenses/>.
//
//
// Image annotation macro originally wrote by Nick McDougall
// 2018/08/30 Zhou Xu modified
// @ Monash Centre for Electron Microscopy
//
// modified to support grey scale, 24bit RGB image formats
// font color auto-adjusted for the background color at the middle point of the line
fontSize = 24;
run("Measure");
label = getResult("Length", nResults-1);
getVoxelSize(width, height, depth, unit);
if (label>10)
label = d2s(label,1);
else
label = d2s(label,2);
label = label + " " + unit;
setJustification("left");
setFont("SansSerif", fontSize);
getLine(x1, y1, x2, y2, lineWidth);
v = getPixel((x1+x2)*0.5,(y1+y2)*0.5);
if (bitDepth==24) {
red = (v>>16)&0xff; // extract red byte (bits 23-17)
green = (v>>8)&0xff; // extract green byte (bits 15-8)
blue = v&0xff; // extract blue byte (bits 7-0)
Luminance = 0.2126 * red + 0.7152 * green + 0.0722 * blue;
}
else {
Luminance = v;
}
if (Luminance <90) {
setColor("white");
}
else {
setColor("black");
}
run("Draw", "slice");
if (label>10)
drawString(label, (x1+x2)*0.5+fontSize*0.5, (y1+y2)*0.5+fontSize*0.5);
else
drawString(label, (x1+x2)*0.5+fontSize*0.5, (y1+y2)*0.5+fontSize*0.5);