1 package com.github.celldynamics.quimp.plugin.generatemask;
2
3 import java.nio.file.Path;
4 import java.nio.file.Paths;
5 import java.util.List;
6
7 import javax.swing.JOptionPane;
8
9 import com.github.celldynamics.quimp.BOAState;
10 import com.github.celldynamics.quimp.Nest;
11 import com.github.celldynamics.quimp.QParamsQconf;
12 import com.github.celldynamics.quimp.QuimP;
13 import com.github.celldynamics.quimp.QuimpException;
14 import com.github.celldynamics.quimp.QuimpException.MessageSinkTypes;
15 import com.github.celldynamics.quimp.Snake;
16 import com.github.celldynamics.quimp.SnakeHandler;
17 import com.github.celldynamics.quimp.filesystem.FileExtensions;
18 import com.github.celldynamics.quimp.plugin.AbstractPluginQconf;
19 import com.github.celldynamics.quimp.plugin.QuimpPluginException;
20 import com.github.celldynamics.quimp.utils.QuimpToolsCollection;
21
22 import ij.IJ;
23 import ij.ImagePlus;
24 import ij.ImageStack;
25 import ij.gui.NewImage;
26 import ij.gui.Roi;
27 import ij.process.ImageConverter;
28 import ij.process.ImageProcessor;
29 import ij.process.StackConverter;
30
31
32
33
34
35
36
37
38
39
40
41 public class GenerateMask_ extends AbstractPluginQconf {
42
43 private static String thisPluginName = "Generate mask";
44
45
46
47
48 private ImagePlus res;
49
50
51
52
53 public GenerateMask_() {
54 super(new GenerateMaskOptions(), thisPluginName);
55 }
56
57
58
59
60
61
62
63
64 public GenerateMask_(String paramString) throws QuimpPluginException {
65 super(paramString, new GenerateMaskOptions(), thisPluginName);
66 }
67
68
69
70
71
72
73 @Override
74 public void run(String arg) {
75 super.run(arg);
76 }
77
78
79
80
81
82
83 @Override
84 public String about() {
85 return "Generate mask plugin.\n" + "Author: Piotr Baniukiewicz\n"
86 + "mail: p.baniukiewicz@warwick.ac.uk";
87 }
88
89
90
91
92
93
94 @Override
95 protected void runFromQconf() throws QuimpException {
96 GenerateMaskOptions/../../com/github/celldynamics/quimp/plugin/generatemask/GenerateMaskOptions.html#GenerateMaskOptions">GenerateMaskOptions opts = (GenerateMaskOptions) options;
97 BOAState bs = qconfLoader.getBOA();
98 Nest nest = bs.nest;
99 int currentColor;
100
101 res = NewImage.createShortImage("test", bs.boap.getWidth(), bs.boap.getHeight(),
102 bs.boap.getFrames(), NewImage.FILL_BLACK);
103
104 ImageStack contourStack = res.getStack();
105 res.setSlice(1);
106 int frame;
107 Snake snake;
108 ImageProcessor contourIp;
109 for (frame = 1; frame <= bs.boap.getFrames(); frame++) {
110 List<Integer> snakes = nest.getSnakesforFrame(frame);
111 contourIp = contourStack.getProcessor(frame);
112 currentColor = 1;
113 for (Integer snakeID : snakes) {
114 SnakeHandler snakeH = nest.getHandlerofId(snakeID);
115 if (snakeH != null) {
116 snake = snakeH.getStoredSnake(frame);
117 Roi roi = snake.asFloatRoi();
118 contourIp.setColor(currentColor++);
119 contourIp.fill(roi);
120 }
121 }
122 }
123 if (opts.binary) {
124 for (int i = 1; i <= res.getImageStackSize(); i++) {
125 res.getStack().getProcessor(i).threshold(0);
126 }
127 ImageConverter.setDoScaling(false);
128 new StackConverter(res).convertToGray8();
129 }
130 if (!apiCall) {
131 res.show();
132
133 QParamsQconf/../../../../../com/github/celldynamics/quimp/QParamsQconf.html#QParamsQconf">QParamsQconf qp = (QParamsQconf) qconfLoader.getQp();
134 Path filename = Paths.get(qp.getPath(), qp.getFileName() + FileExtensions.generateMaskSuffix);
135 IJ.saveAsTiff(res, filename.toString());
136 IJ.log("Saved in: " + filename.toString());
137 if (errorSink == MessageSinkTypes.GUI) {
138 JOptionPane.showMessageDialog(
139 IJ.getInstance(), QuimpToolsCollection
140 .stringWrap("Image saved! (" + filename.toString() + ")", QuimP.LINE_WRAP),
141 "Saved!", JOptionPane.INFORMATION_MESSAGE);
142 } else {
143 IJ.log("Mask generated!");
144 }
145 }
146
147 }
148
149
150
151
152
153
154
155
156
157 public ImagePlus getRes() {
158 return res;
159 }
160
161 @Override
162 protected void runFromPaqp() throws QuimpException {
163 throw new QuimpException("Old file format is not supported");
164 }
165
166
167
168
169
170
171 @Override
172 public void showUi(boolean val) throws Exception {
173
174 loadFile(options.paramFile);
175
176 options.paramFile = qconfLoader.getQp().getParamFile().getAbsolutePath();
177 }
178 }