1 package com.github.celldynamics.quimp.utils;
2
3 import java.util.concurrent.TimeUnit;
4
5 import ij.ImageJ;
6 import ij.ImagePlus;
7 import ij.WindowManager;
8 import ij.plugin.RGBStackMerge;
9 import ij.process.ColorProcessor;
10 import ij.process.ImageProcessor;
11 import ij.process.LUT;
12
13
14
15
16
17
18
19 public class IJTools {
20
21
22
23
24
25
26 public static int WAIT_TIME = 2;
27
28
29
30
31
32
33
34
35
36 public static ImagePlus getComposite(ImagePlus org, ImagePlus small, ImagePlus big) {
37 ImagePlus ret = RGBStackMerge
38 .mergeChannels(new ImagePlus[] { small, big, null, org, null, null, null }, false);
39 return ret;
40 }
41
42
43
44
45
46
47
48
49
50
51
52 public static ColorProcessor getRGB(ImagePlus red, ImagePlus green, ImagePlus blue) {
53 return getRGB(red.getProcessor(), green.getProcessor(), blue.getProcessor());
54 }
55
56
57
58
59
60
61
62
63
64
65
66 public static ColorProcessor getRGB(ImageProcessor red, ImageProcessor green,
67 ImageProcessor blue) {
68 ColorProcessor ret = new ColorProcessor(red.getWidth(), red.getHeight());
69
70 ret.setChannel(1, red.convertToByteProcessor());
71 ret.setChannel(2, green.convertToByteProcessor());
72 ret.setChannel(3, blue.convertToByteProcessor());
73 return ret;
74 }
75
76
77
78
79
80
81 public static LUT getGrayLut() {
82 byte[] l = new byte[256];
83 for (int i = 0; i < 256; i++) {
84 l[i] = (byte) i;
85 }
86 return new LUT(l, l, l);
87 }
88
89
90
91
92 public static void closeAllImages() {
93 int[] img = WindowManager.getIDList();
94 if (img != null) {
95 for (int s : img) {
96 ImagePlus id = WindowManager.getImage(s);
97 if (id != null) {
98 id.changes = false;
99 }
100 }
101 }
102 WindowManager.closeAllWindows();
103 }
104
105
106
107
108
109
110
111
112 public static void exitIj(ImageJ ij) throws InterruptedException {
113 if (ij != null) {
114 ij.quit();
115 TimeUnit.SECONDS.sleep(WAIT_TIME);
116 }
117 }
118
119 }