BioImager  3.9.1
A .NET microscopy imaging library. Supports various microscopes by using imported libraries & GUI automation. Supported libraries include PriorĀ® & ZeissĀ® & all devices supported by Micromanager 2.0 and python-microscope.
Loading...
Searching...
No Matches
BioImager.ImageJ Class Reference

Classes

class  Macro
 
class  RoiDecoder
 
class  RoiEncoder
 

Static Public Member Functions

static void RunMacro (string file, string param)
 
static void RunString (string con, string param, bool headless)
 
static void RunOnImage (string con, bool headless, bool onTab, bool bioformats, bool newTab)
 
static bool Initialize ()
 
static bool SetImageJPath ()
 

Static Public Attributes

static List< Macro.CommandMacros = new List<Macro.Command>()
 
static List< Process > processes = new List<Process>()
 
static string ImageJPath = Properties.Settings.Default.ImageJPath
 

Properties

static bool Initialized [get]
 

Detailed Description

Definition at line 17 of file ImageJ.cs.

Member Function Documentation

◆ Initialize()

static bool BioImager.ImageJ.Initialize ( )
static

This function is used to initialize the path of the ImageJ.exe file

Parameters
pathThe path to the ImageJ executable.

Definition at line 247 of file ImageJ.cs.

248 {
249 if (!SetImageJPath())
250 return false;
251 Macro.Initialize();
252 string[] ds = Directory.GetFiles(Path.GetDirectoryName(ImageJPath) + "/macros");
253 foreach (string s in ds)
254 {
255 if (s.EndsWith(".ijm") || s.EndsWith(".txt"))
256 Macros.Add(new Macro.Command(Path.GetFileName(s), "", ""));
257 }
258 return true;
259 }
static bool SetImageJPath()
Definition: ImageJ.cs:263

References BioImager.ImageJ.SetImageJPath().

Referenced by BioImager.App.Initialize(), BioImager.ImageJ.RunMacro(), BioImager.ImageJ.RunOnImage(), and BioImager.ImageJ.RunString().

◆ RunMacro()

static void BioImager.ImageJ.RunMacro ( string  file,
string  param 
)
static

It runs a macro in ImageJ

Parameters
filethe path to the macro file
param
Returns
The macro is being returned.

Definition at line 115 of file ImageJ.cs.

116 {
117 if(!Initialized)
118 {
119 Initialize();
120 }
121 file.Replace("/", "\\");
122 Process pr = new Process();
123 pr.StartInfo.FileName = ImageJPath;
124 pr.StartInfo.Arguments = "-macro " + file + " " + param;
125
126 pr.Start();
127 processes.Add(pr);
128 Recorder.AddLine("ImageJ.RunMacro(" + file + "," + '"' + param + '"' + ");");
129 }
static bool Initialize()
Definition: ImageJ.cs:247

References BioImager.ImageJ.Initialize().

Referenced by BioImager.Imager.PerformFunction().

◆ RunOnImage()

static void BioImager.ImageJ.RunOnImage ( string  con,
bool  headless,
bool  onTab,
bool  bioformats,
bool  newTab 
)
static

It runs a macro on the selected image, saves the result as a new image, and then opens the new image in a new tab

Parameters
conThe ImageJ macro to run.
headlessWhether to run ImageJ in headless mode.
onTabWhether to run the macro on current tab of images.
bioformatsIf the image is a bioformats image, it will use the bioformats importer to open the image.
newTabWhether or not the result should open in a new tab.
Returns
The return value is the result of the last statement in the script.

Definition at line 189 of file ImageJ.cs.

190 {
191 if (!Initialized)
192 {
193 Initialize();
194 }
195 string filename = "";
196 string dir = Path.GetDirectoryName(ImageView.SelectedImage.file);
197
198 if (ImageView.SelectedImage.ID.EndsWith(".ome.tif"))
199 {
200 filename = Path.GetFileNameWithoutExtension(ImageView.SelectedImage.ID);
201 filename = filename.Remove(filename.Length - 4, 4);
202 }
203 else
204 filename = Path.GetFileNameWithoutExtension(ImageView.SelectedImage.ID);
205 string file = dir + "\\" + filename + "-temp" + ".ome.tif";
206 file = file.Replace("\\", "/");
207 string st =
208 "run(\"Bio-Formats Importer\", \"open=\" + getArgument + \" autoscale color_mode=Default open_all_series display_rois rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT\"); " + con +
209 "run(\"Bio-Formats Exporter\", \"save=" + file + " export compression=Uncompressed\"); " +
210 "dir = getDir(\"startup\"); " +
211 "File.saveString(\"done\", dir + \"/done.txt\");";
212 if(bioformats)
213 st =
214 "open(getArgument); " + con +
215 "run(\"Bio-Formats Exporter\", \"save=" + file + " export compression=Uncompressed\"); " +
216 "dir = getDir(\"startup\"); " +
217 "File.saveString(\"done\", dir + \"/done.txt\");";
218 //We save the image as a temp image as otherwise imagej won't export due to file access error.
219 RunString(st, ImageView.SelectedImage.file, headless);
220
221 if (!File.Exists(file))
222 return;
223
224 string ffile = dir + "/" + filename + ".ome.tif";
225 File.Delete(ffile);
226 File.Copy(file, ffile);
227 File.Delete(file);
228 if (ImageView.SelectedImage.Filename != filename + ".ome.tif" || ImageView.SelectedImage.Filename != filename + ".tif")
229 {
230 if (ImageView.SelectedImage.filename.EndsWith(".tif"))
231 BioImage.OpenFile(ffile, newTab);
232 else
233 BioImage.OpenFile(ffile, true);
234 }
235 else
236 {
237 App.viewer.Images[App.viewer.SelectedIndex] = BioImage.OpenFile(ffile, 0, false, false);
238 }
239 App.viewer.UpdateImage();
240 App.viewer.UpdateView();
241 Recorder.AddLine("RunOnImage(\"" + con + "\"," + headless + "," + onTab + "," + newTab + ");");
242 }
static void RunString(string con, string param, bool headless)
Definition: ImageJ.cs:137

References BioImager.ImageJ.Initialize(), BioImager.BioImage.OpenFile(), BioImager.ImageJ.RunString(), BioImager.ImageView.SelectedIndex, BioImager.ImageView.UpdateImage(), and BioImager.ImageView.UpdateView().

Referenced by BioImager.Function.PerformFunction().

◆ RunString()

static void BioImager.ImageJ.RunString ( string  con,
string  param,
bool  headless 
)
static

It runs a macro in ImageJ

Parameters
conThe macro code
paramThe parameters to pass to the macro.
headlesswhether or not to run ImageJ in headless mode
Returns
The macro is returning a string.

Definition at line 137 of file ImageJ.cs.

138 {
139 if (!Initialized)
140 {
141 Initialize();
142 }
143 Process pr = new Process();
144 pr.StartInfo.FileName = ImageJPath;
145 pr.StartInfo.CreateNoWindow = true;
146 string te = rng.Next(0, 9999999).ToString();
147 string p = Environment.CurrentDirectory + "\\" + te + ".txt";
148 p.Replace("/", "\\");
149 File.WriteAllText(p,con);
150 if(headless)
151 pr.StartInfo.Arguments = "--headless -macro " + p + " " + param;
152 else
153 pr.StartInfo.Arguments = "-macro " + p + " " + param;
154 pr.Start();
155 File.Delete(Path.GetDirectoryName(ImageJPath) + "/done.txt");
156 processes.Add(pr);
157 do
158 {
159 if (File.Exists(Path.GetDirectoryName(ImageJPath) + "/done.txt"))
160 {
161 do
162 {
163 try
164 {
165 File.Delete(Path.GetDirectoryName(ImageJPath) + "/done.txt");
166 }
167 catch (Exception)
168 {
169
170 }
171 } while (File.Exists(Path.GetDirectoryName(ImageJPath) + "/done.txt"));
172 pr.Kill();
173 break;
174 }
175 } while (!pr.HasExited);
176 File.Delete(p);
177 }

References BioImager.ImageJ.Initialize().

Referenced by BioImager.ImageJ.RunOnImage().

◆ SetImageJPath()

static bool BioImager.ImageJ.SetImageJPath ( )
static

If the ImageJ path is not set, prompt the user to set it

Returns
The return value is a boolean.

Definition at line 263 of file ImageJ.cs.

264 {
265 if (Properties.Settings.Default.ImageJPath == "")
266 {
267 MessageBox.Show("ImageJ path not set. Set the ImageJ executable location.");
268 OpenFileDialog file = new OpenFileDialog();
269 file.Title = "Set the ImageJ executable location.";
270 if (file.ShowDialog() != DialogResult.OK)
271 return false;
272 Properties.Settings.Default.ImageJPath = file.FileName;
273 Properties.Settings.Default.Save();
274 ImageJPath = file.FileName;
275 init = true;
276 file.Dispose();
277 return true;
278 }
279 else
280 return true;
281 }

Referenced by BioImager.ImageJ.Initialize().

Member Data Documentation

◆ ImageJPath

string BioImager.ImageJ.ImageJPath = Properties.Settings.Default.ImageJPath
static

Definition at line 105 of file ImageJ.cs.

◆ Macros

List<Macro.Command> BioImager.ImageJ.Macros = new List<Macro.Command>()
static

Definition at line 103 of file ImageJ.cs.

◆ processes

List<Process> BioImager.ImageJ.processes = new List<Process>()
static

Definition at line 104 of file ImageJ.cs.

Property Documentation

◆ Initialized

bool BioImager.ImageJ.Initialized
staticget

Definition at line 108 of file ImageJ.cs.

108{ get { return init; } private set { } }

The documentation for this class was generated from the following file: