BioLib  4.3.0
A GUI-less version of Bio .NET library for editing & annotating various microscopy image formats.
Loading...
Searching...
No Matches
BioLib.Fiji Class Reference

Classes

class  Macro
 
class  RoiDecoder
 
class  RoiEncoder
 

Static Public Member Functions

static ImagePlus GetImagePlus (BioImage bm)
 
static bool isRGB (ImagePlus image)
 
static int[] getRGBPixelsFromSlice (ImageStack stack, int sliceIndex)
 
static BioImage GetBioImage (ImagePlus pl, VolumeD vol, double PhysicalX, double PhysicalY, double PhysicalZ)
 Converts ImagePlus to BioImage.
 
static BioImage RunImageJ (BioImage b, string file, string param)
 
static void RunMacroFiji (BioImage b, string macrofile, string param)
 
static async Task< BioImage > RunStringFiji (BioImage b, string con, string param, bool headless, string outputPath=null)
 
static async Task< BioImage > RunOnImageFiji (BioImage b, string con, int index, bool headless, bool onTab, bool bioformats, bool resultInNewTab)
 
static BioImage RunOnImageInProcess (BioImage b, string con, bool headless, bool bioformats, bool resultInNewTab, bool registerWithImages=true)
 
static bool CanParameterizeInteractiveRunCommand (string con)
 
static bool TryParameterizeInteractiveRunCommand (BioImage previewImage, string con, bool headless, bool resultInNewTab, out string parameterizedCommand)
 
static async Task< BioImage > RunOnImage (BioImage b, string con, bool headless, bool onTab, bool useBioformats, bool resultInNewTab)
 
static bool Initialize (string path)
 

Static Public Attributes

static List< Process > processes = new List<Process>()
 
static List< Macro.Command > Macros = new List<Macro.Command>()
 

Properties

static bool Initialized [get]
 
static string ImageJPath [get, set]
 
static string ImageJMacroPath [get]
 
static bool UseFiji [get]
 

Member Function Documentation

◆ CanParameterizeInteractiveRunCommand()

static bool BioLib.Fiji.CanParameterizeInteractiveRunCommand ( string con)
static
703 {
704 return TryExtractBareRunCommand(con, out _);
705 }

◆ GetBioImage()

static BioImage BioLib.Fiji.GetBioImage ( ImagePlus pl,
VolumeD vol,
double PhysicalX,
double PhysicalY,
double PhysicalZ )
static

Converts ImagePlus to BioImage.

Parameters
pl
maxz
maxc
maxt
location
Returns
The BioImage represented by the ImagePlus object.
322 {
323 BioImage bm = new BioImage(pl.getTitle());
324 ImageStack st = pl.getImageStack();
325 int b = pl.getBitDepth();
326 int slices = pl.getNSlices();
327 int chs = pl.getNChannels();
328 int frs = pl.getNFrames();
329 int rgb = (int)(pl.getBytesPerPixel() * 8);
330 bool isrgb = isRGB(pl);
331 bm.StackOrder = BioImage.Order.ZCT;
332 bm.UpdateCoords(slices, chs, frs, BioImage.Order.ZCT);
333 AForge.Bitmap[] outputBuffers = new AForge.Bitmap[Math.Max(1, slices * chs * frs)];
334 for (int t = 0; t < frs; t++)
335 {
336 for (int z = 0; z < slices; z++)
337 {
338 for (int c = 0; c < chs; c++)
339 {
340 AForge.Bitmap bmp;
341 if (!isrgb)
342 {
343 if (rgb > 8)
344 {
345 bmp = new AForge.Bitmap(st.getWidth(), st.getHeight(), AForge.PixelFormat.Format16bppGrayScale);
346 }
347 else
348 {
349 bmp = new AForge.Bitmap(st.getWidth(), st.getHeight(), AForge.PixelFormat.Format8bppIndexed);
350 }
351 }
352 else
353 {
354 bmp = new AForge.Bitmap(st.getWidth(), st.getHeight(), AForge.PixelFormat.Format24bppRgb);
355 }
356 int ind = bm.GetFrameIndex(z, c, t);
357 int stackIndex = GetHyperStackSliceIndex(pl, z, c, t);
358 outputBuffers[ind] = bmp;
359 if (!isrgb)
360 {
361 for (int y = 0; y < pl.getHeight(); y++)
362 {
363 for (int x = 0; x < pl.getWidth(); x++)
364 {
365 double d = st.getVoxel(x, y, stackIndex);
366 if (bmp.PixelFormat == PixelFormat.Format16bppGrayScale)
367 bmp.SetValue(x, y, (ushort)d);
368 else if (bmp.PixelFormat == PixelFormat.Format8bppIndexed)
369 bmp.SetValue(x, y, (byte)d);
370 }
371 }
372 }
373 else
374 {
375 ImageProcessor ip = st.getProcessor(stackIndex + 1); // ImageStack uses 1-based indexing
376 // Cast to ColorProcessor to access RGB data
377 ColorProcessor colorProcessor = (ColorProcessor)ip;
378 for (int y = 0; y < pl.getHeight(); y++)
379 {
380 for (int x = 0; x < pl.getWidth(); x++)
381 {
382 int v = colorProcessor.getPixel(x, y);
383 int rv = (v >> 16) & 0xFF; // Red
384 int gv = (v >> 8) & 0xFF; // Green
385 int bv = v & 0xFF; // Blue
386 bmp.SetValue(x, y, 0, (byte)rv);
387 bmp.SetValue(x, y, 1, (byte)gv);
388 bmp.SetValue(x, y, 2, (byte)bv);
389 }
390 }
391
392 }
393 }
394 }
395 }
396 bm.Buffers.AddRange(outputBuffers.Where(buf => buf != null));
397 for (int t = 0; t < chs; t++)
398 {
399 if (isrgb)
400 bm.Channels.Add(new AForge.Channel(t, rgb, 3));
401 else
402 bm.Channels.Add(new AForge.Channel(t, rgb, 1));
403 if (t == 0)
404 {
405 bm.rgbChannels[0] = 0;
406 }
407 else
408 if (t == 1)
409 {
410 bm.rgbChannels[1] = 1;
411 }
412 else
413 if (t == 2)
414 {
415 bm.rgbChannels[2] = 2;
416 }
417 }
418 bm.Resolutions.Add(new Resolution(pl.getWidth(), pl.getHeight(), bm.Buffers[0].PixelFormat, PhysicalX, PhysicalY, PhysicalZ, vol.Location.X, vol.Location.Y, vol.Location.X));
419 bm.Volume = vol;
420 bm.littleEndian = BitConverter.IsLittleEndian;
421 bm.seriesCount = 1;
422 BioImage.AutoThreshold(bm, true);
423 if (rgb > 8)
424 bm.StackThreshold(true);
425 else
426 bm.StackThreshold(false);
427
428 if (bm.RGBChannelCount == 4)
429 {
430 bm.Channels.Last().SamplesPerPixel = 4;
431 }
432 return bm;
433 }
AForge.PixelFormat PixelFormat
Definition Bio.cs:58
return b
Definition Bio.cs:7393
static Bitmap bm
Definition Bio.cs:8524
FijiNet::ij.process.ColorProcessor ColorProcessor
Definition Fiji.cs:18
FijiNet::ij.ImageStack ImageStack
Definition Fiji.cs:24
FijiNet::ij.process.ImageProcessor ImageProcessor
Definition Fiji.cs:23
Definition Bio.cs:1872
Order
Definition Bio.cs:2898
static bool isRGB(ImagePlus image)
Definition Fiji.cs:299
Definition Bio.cs:203

◆ GetImagePlus()

static ImagePlus BioLib.Fiji.GetImagePlus ( BioImage bm)
static
184 {
185 ImageStack ims = new ImageStack(bm.SizeX, bm.SizeY);
186 if (bm.Buffers[0].PixelFormat == AForge.PixelFormat.Format16bppGrayScale)
187 {
188 // Populate the stack with 16-bit images
189 for (int t = 0; t < bm.SizeT; t++)
190 {
191 for (int z = 0; z < bm.SizeZ; z++)
192 {
193 for (int c = 0; c < bm.SizeC; c++)
194 {
195 short[] pixels = ConvertByteArrayToShortArray(bm.Buffers[bm.GetFrameIndex(z, c, t)].Bytes, true);
196 ImageProcessor ip = new ShortProcessor(bm.SizeX, bm.SizeY, pixels, java.awt.image.ColorModel.getRGBdefault());
197 ims.addSlice("Z" + z + "C" + c + "T" + t, ip);
198 }
199 }
200 }
201 }
202 else if (bm.Buffers[0].PixelFormat == AForge.PixelFormat.Format8bppIndexed)
203 {
204 // Create a grayscale IndexColorModel
205 byte[] grayscale = new byte[256];
206 for (int i = 0; i < 256; i++)
207 {
208 grayscale[i] = (byte)i;
209 }
210 IndexColorModel colorModel = new IndexColorModel(8, 256, grayscale, grayscale, grayscale);
211 for (int t = 0; t < bm.SizeT; t++)
212 {
213 for (int z = 0; z < bm.SizeZ; z++)
214 {
215 for (int c = 0; c < bm.SizeC; c++)
216 {
217 ImageProcessor ip = new ByteProcessor(bm.SizeX, bm.SizeY, bm.Buffers[bm.GetFrameIndex(z, c, t)].Bytes, colorModel);
218 ims.addSlice("Z" + z + "C" + c + "T" + t, ip);
219 }
220 }
221 }
222 }
223 else if (bm.Buffers[0].PixelFormat == AForge.PixelFormat.Format24bppRgb)
224 {
225 for (int t = 0; t < bm.SizeT; t++)
226 {
227 for (int z = 0; z < bm.SizeZ; z++)
228 {
229 for (int c = 0; c < bm.SizeC; c++)
230 {
231 byte[] bts = bm.Buffers[bm.GetFrameIndex(z, c, t)].Bytes;
232 // Convert the byte array to an int array for the RGB processor
233 int[] rgbPixels = new int[bm.SizeX * bm.SizeY];
234 for (int i = 0; i < rgbPixels.Length; i++)
235 {
236 int r = bts[i * 3] & 0xFF; // Red
237 int g = bts[i * 3 + 1] & 0xFF; // Green
238 int b = bts[i * 3 + 2] & 0xFF; // Blue
239 rgbPixels[i] = (r << 16) | (g << 8) | b; // Combine into RGB int
240 }
241 // Create a ColorProcessor
242 ImageProcessor ip = new ColorProcessor(bm.SizeX, bm.SizeY, rgbPixels);
243 ims.addSlice("Z" + z + "C" + c + "T" + t, ip);
244 }
245 }
246 }
247 }
248 else if (bm.Buffers[0].PixelFormat == AForge.PixelFormat.Format32bppArgb || bm.Buffers[0].PixelFormat == AForge.PixelFormat.Format32bppRgb)
249 {
250 for (int t = 0; t < bm.SizeT; t++)
251 {
252 for (int z = 0; z < bm.SizeZ; z++)
253 {
254 for (int c = 0; c < bm.SizeC; c++)
255 {
256 byte[] bts = bm.Buffers[bm.GetFrameIndex(z, c, t)].Bytes;
257 // Convert the byte array to an int array for the ColorProcessor
258 int[] rgbaPixels = new int[bm.SizeX * bm.SizeY];
259 for (int i = 0; i < rgbaPixels.Length; i++)
260 {
261 int r = bts[i * 4] & 0xFF; // Red
262 int g = bts[i * 4 + 1] & 0xFF; // Green
263 int b = bts[i * 4 + 2] & 0xFF; // Blue
264 int a = bts[i * 4 + 3] & 0xFF; // Alpha
265 rgbaPixels[i] = (a << 24) | (r << 16) | (g << 8) | b; // Combine into ARGB int
266 }
267 // Create a ColorProcessor with the ARGB int array
268 ImageProcessor ip = new ColorProcessor(bm.SizeX, bm.SizeY, rgbaPixels);
269 ims.addSlice("Z" + z + "C" + c + "T" + t, ip);
270 }
271 }
272 }
273 }
274 else if (bm.Buffers[0].PixelFormat == AForge.PixelFormat.Format48bppRgb)
275 {
276 bm.To16Bit();
277 // Populate the stack with 16-bit images
278 for (int t = 0; t < bm.SizeT; t++)
279 {
280 for (int z = 0; z < bm.SizeZ; z++)
281 {
282 for (int c = 0; c < bm.SizeC; c++)
283 {
284 short[] pixels = ConvertByteArrayToShortArray(bm.Buffers[bm.GetFrameIndex(z, c, t)].Bytes, true);
285 ImageProcessor ip = new ShortProcessor(bm.SizeX, bm.SizeY, pixels, java.awt.image.ColorModel.getRGBdefault());
286 ims.addSlice("Z" + z + "C" + c + "T" + t, ip);
287 }
288 }
289 }
290 }
291 ImagePlus imp = new ImagePlus(bm.ID, ims);
292 imp.setDimensions(bm.SizeC, bm.SizeZ, bm.SizeT);
293 return imp;
294 }
java.awt.image.IndexColorModel IndexColorModel
Definition Fiji.cs:25
FijiNet::ij.process.ShortProcessor ShortProcessor
Definition Fiji.cs:29
FijiNet::ij.process.ByteProcessor ByteProcessor
Definition Fiji.cs:17
FijiNet::ij.ImagePlus ImagePlus
Definition Fiji.cs:22

◆ getRGBPixelsFromSlice()

static int[] BioLib.Fiji.getRGBPixelsFromSlice ( ImageStack stack,
int sliceIndex )
static
304 {
305 // Get the ImageProcessor for the specified slice
306 ImageProcessor ip = stack.getProcessor(sliceIndex + 1); // ImageStack uses 1-based indexing
307 // Cast to ColorProcessor to access RGB data
308 ColorProcessor colorProcessor = (ColorProcessor)ip;
309 // Get the RGB pixel data
310 return (int[])colorProcessor.getPixels();
311 }

◆ Initialize()

static bool BioLib.Fiji.Initialize ( string path)
static

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

Parameters
pathThe path to the ImageJ executable.
895 {
896 Macro.Initialize();
897 ImageJPath = path;
898 return true;
899 }
static string ImageJPath
Definition Fiji.cs:123

◆ isRGB()

static bool BioLib.Fiji.isRGB ( ImagePlus image)
static
300 {
301 return image.getType() == ImagePlus.COLOR_RGB;
302 }

◆ RunImageJ()

static BioImage BioLib.Fiji.RunImageJ ( BioImage b,
string file,
string param )
static
439 {
440 if (!init)
441 RunMacroFiji(b, file, param);
442 Console.WriteLine("RunImageJ(" + file + "," + param);
444 Console.WriteLine("Fiji.GetImagePlus(" + b.ToString() + ")");
445 WindowManager.setTempCurrentImage(ip);
446 Console.WriteLine("WindowManager.setTempCurrentImage(" + ip.ToString() + ")");
447 IJ.runMacroFile(file, param);
448 BioImage bm = GetBioImage(ip, b.Volume, b.PhysicalSizeX, b.PhysicalSizeY, b.PhysicalSizeZ);
449 int i = Images.GetImageCountByName(bm.Filename);
450 if (bm.Filename.EndsWith("-" + i))
451 bm.Filename.Replace("-" + i, "-" + (i + 1).ToString());
452 return bm;
453 }
override string ToString()
This function returns the filename of the object, and the location of the object in the 3D space.
Definition Bio.cs:11736
FijiNet::ij.WindowManager WindowManager
Definition Fiji.cs:30
FijiNet::ij.IJ IJ
Definition Fiji.cs:20
static BioImage GetBioImage(ImagePlus pl, VolumeD vol, double PhysicalX, double PhysicalY, double PhysicalZ)
Converts ImagePlus to BioImage.
Definition Fiji.cs:321
static ImagePlus GetImagePlus(BioImage bm)
Definition Fiji.cs:183
static void RunMacroFiji(BioImage b, string macrofile, string param)
Definition Fiji.cs:460
Definition Bio.cs:68
static int GetImageCountByName(string s)
Definition Bio.cs:104

◆ RunMacroFiji()

static void BioLib.Fiji.RunMacroFiji ( BioImage b,
string macrofile,
string param )
static

It runs a macro in ImageJ

Parameters
filethe path to the macro file
paramThe parameter to pass to the macro.
Returns
The macro is being returned.
461 {
462 if (UseFiji)
463 {
464 Process pr = new Process();
465 pr.StartInfo.FileName = ImageJPath;
466 pr.StartInfo.Arguments = "-macro " + macrofile + " " + param;
467 pr.Start();
468 processes.Add(pr);
469 }
470 else
471 {
472 RunImageJ(b, b.file, param);
473 }
474 BioLib.Recorder.Record($"Fiji.RunMacroFiji({b}, \"{macrofile}\", \"{param}\");");
475 }
static bool UseFiji
Definition Fiji.cs:149
static List< Process > processes
Definition Fiji.cs:435
static BioImage RunImageJ(BioImage b, string file, string param)
Definition Fiji.cs:438
Definition Recorder.cs:12
static void Record(MethodInfo inf, bool isInternal, params object[] args)
Definition Recorder.cs:20
Definition Bio.cs:65

◆ RunOnImage()

static async Task< BioImage > BioLib.Fiji.RunOnImage ( BioImage b,
string con,
bool headless,
bool onTab,
bool useBioformats,
bool resultInNewTab )
static
858 {
859 if (b != null && b.isPyramidal)
860 return await ImageJ.RunOnAllPyramidLevels(b, con, headless, onTab, useBioformats, resultInNewTab).ConfigureAwait(false);
861 BioImage bm;
862 if (UseFiji || OperatingSystem.IsMacOS())
863 bm = await RunOnImageFiji(b, con, 0, headless, onTab, useBioformats, resultInNewTab);
864 else
865 {
866 bioImage = b;
867 cons = con;
868 indexs = 0;
869 Fiji.headless = headless;
870 bioformats = useBioformats;
871 resultInNewTabs = resultInNewTab;
872 Recorder.Record($"Fiji.RunOnImage({b}, \"{con}\", {headless.ToString().ToLower()}, {onTab.ToString().ToLower()}, {useBioformats.ToString().ToLower()}, {resultInNewTab.ToString().ToLower()});");
873 return RunImageJ();
874 }
875 return bm;
876 }
static async Task< BioImage > RunOnImageFiji(BioImage b, string con, int index, bool headless, bool onTab, bool bioformats, bool resultInNewTab)
Definition Fiji.cs:550
Definition ImageJ.cs:18
static async Task< BioImage > RunOnAllPyramidLevels(BioImage b, string con, bool headless, bool onTab, bool bioformats, bool resultInNewTab)
Runs an ImageJ command on every pyramid level and returns a single pyramidal BioImage assembled from ...
Definition ImageJ.cs:924

◆ RunOnImageFiji()

static async Task< BioImage > BioLib.Fiji.RunOnImageFiji ( BioImage b,
string con,
int index,
bool headless,
bool onTab,
bool bioformats,
bool resultInNewTab )
static

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

Parameters
conThe ImageJ macro to run on the image.
headlessWhether to run ImageJ in headless mode.
onTabIf true, the imacro will be run on tab. If false, the macro will be run on selected image.
bioformatsIf true, the image is opened using the bioformats plugin. If false, the image is opened using the default imagej open command.
Returns
The image is being returned as a new tab.
551 {
552 if (UseFiji || OperatingSystem.IsMacOS())
553 {
554 string filename = "";
555 string dir = Path.GetDirectoryName(b.file);
556 dir = dir.Replace("\\", "/");
557 if (b.ID.EndsWith(".ome.tif"))
558 {
559 filename = Path.GetFileNameWithoutExtension(b.ID);
560 filename = filename.Remove(filename.Length - 4, 4);
561 }
562 else
563 filename = Path.GetFileNameWithoutExtension(b.ID);
564 string file = dir + "/" + filename + ".ome.tif";
565 string filet = dir + "/" + filename + "-temp.ome.tif";
566 if (!bioformats)
567 file = dir + "/" + filename + ".tif";
568 string outputFile = bioformats ? filet : filet + ".tif";
569 string roiZip = ExportRoiZipForFiji(b, filename);
570 string donepath = Path.GetDirectoryName(Environment.ProcessPath);
571 donepath = donepath.Replace("\\", "/");
572 string op = b.ID.Replace("\\", "/");
573 string ex = Path.GetExtension(b.ID);
574 op = op.Replace(ex, ".ome.tif");
575 //if (File.Exists(file))
576 // File.Delete(file);
577 BioImage cleanInput = BioImage.Copy(b, false);
578 BioImage.SaveOME(cleanInput, file);
579 string st =
580 "run(\"Bio-Formats Importer\", \"open=" + file + " autoscale color_mode=Default open_all_series display_rois rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT\"); " + con +
581 "roiManager(\"Show None\"); run(\"Select None\"); " +
582 "run(\"Bio-Formats Exporter\", \"save=" + filet + " export compression=Uncompressed\"); " +
583 "dir = \"" + donepath + "\"" +
584 "File.saveString(\"done\", dir + \"/done.txt\");";
585 if (!bioformats)
586 st =
587 "open(getArgument); " +
588 (!string.IsNullOrWhiteSpace(roiZip)
589 ? "roiManager(\"Reset\"); roiManager(\"Open\", \"" + roiZip.Replace("\\", "/") + "\"); roiManager(\"Show All\"); "
590 : string.Empty) +
591 con +
592 "roiManager(\"Show None\"); run(\"Select None\"); " +
593 "saveAs(\"Tiff\",\"" + outputFile + "\"); " +
594 "dir = \"" + donepath + "\"" +
595 "File.saveString(\"done\", dir + \"/done.txt\");";
596
597 BioImage bm = await Fiji.RunStringFiji(b, st, "", headless, outputFile);
598 if (File.Exists(file) && bioformats)
599 File.Delete(file);
600 BioLib.Recorder.Record($"Fiji.RunOnImageFiji({b}, \"{con}\", {index}, {headless.ToString().ToLower()}, {onTab.ToString().ToLower()}, {bioformats.ToString().ToLower()}, {resultInNewTab.ToString().ToLower()});");
601 return bm;
602 }
603 else
604 {
605 cons = con;
606 indexs = index;
607 Fiji.headless = headless;
608 onTabs = onTab;
609 Fiji.bioformats = bioformats;
610 resultInNewTabs = resultInNewTab;
611 bioImage = b;
612 Task<BioImage> t = new Task<BioImage>(() => RunImageJ());
613 t.Start();
614 t.Wait();
615 BioLib.Recorder.Record($"Fiji.RunOnImageFiji({b}, \"{con}\", {index}, {headless.ToString().ToLower()}, {onTab.ToString().ToLower()}, {bioformats.ToString().ToLower()}, {resultInNewTab.ToString().ToLower()});");
616 return t.Result;
617 }
618 }
System.IO.Path Path
Definition Bio.cs:57
static BioImage Copy(BioImage b, bool rois)
Definition Bio.cs:2133
Definition Fiji.cs:35
static async Task< BioImage > RunStringFiji(BioImage b, string con, string param, bool headless, string outputPath=null)
Definition Fiji.cs:483

◆ RunOnImageInProcess()

static BioImage BioLib.Fiji.RunOnImageInProcess ( BioImage b,
string con,
bool headless,
bool bioformats,
bool resultInNewTab,
bool registerWithImages = true )
static
689 {
690 lock (imageJRunLock)
691 {
692 cons = con;
693 indexs = 0;
694 Fiji.headless = headless;
695 Fiji.bioformats = bioformats;
696 resultInNewTabs = resultInNewTab;
697 bioImage = b;
698 return RunImageJ(registerWithImages);
699 }
700 }

◆ RunStringFiji()

static async Task< BioImage > BioLib.Fiji.RunStringFiji ( BioImage b,
string con,
string param,
bool headless,
string outputPath = null )
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
Nothing.
484 {
485 Process pr = new Process();
486 pr.StartInfo.FileName = ImageJPath;
487 string te = rng.Next(0, 9999999).ToString();
488 string p = Path.GetDirectoryName(Environment.ProcessPath) + "/" + te;
489 if (OperatingSystem.IsMacOS())
490 {
491 Console.WriteLine(p);
492 pr.StartInfo.UseShellExecute = true;
493 }
494 File.WriteAllText(p, con);
495 if (headless)
496 pr.StartInfo.Arguments = "--headless -macro " + p + " " + param;
497 else
498 pr.StartInfo.Arguments = "-macro " + p + " " + param;
499 pr.Start();
500 string donedir = Path.GetDirectoryName(Environment.ProcessPath);
501 donedir = donedir.Replace("\\", "/");
502 File.Delete(Path.GetDirectoryName(Environment.ProcessPath) + "/done.txt");
503 processes.Add(pr);
504 do
505 {
506 if (File.Exists(donedir + "/done.txt"))
507 {
508 do
509 {
510 try
511 {
512 File.Delete(donedir + "/done.txt");
513 }
514 catch (Exception)
515 {
516
517 }
518 } while (File.Exists(donedir + "/done.txt"));
519 pr.Kill();
520 break;
521 }
522 } while (!pr.HasExited);
523 Console.WriteLine("Deleting temp file:" + p);
524 File.Delete(p);
525 string f = outputPath;
526 if (string.IsNullOrWhiteSpace(f))
527 {
528 Console.WriteLine("Directory: " + Path.GetDirectoryName(b.file));
529 Console.WriteLine("FileName: " + Path.GetFileNameWithoutExtension(b.file));
530 f = Path.GetDirectoryName(b.file) + "/" + Path.GetFileNameWithoutExtension(b.file) + "-temp.ome.tif";
531 }
532 Console.WriteLine("Opening: " + f);
533 if (File.Exists(f))
534 await BioImage.OpenAsync(f, true, true, true, 0);
535 Console.WriteLine("GetImage: " + f);
537 BioLib.Recorder.Record($"Fiji.RunStringFiji({b}, \"{con}\", \"{param}\", {headless.ToString().ToLower()});");
538 return bm;
539 }
static BioImage GetImage(string ids)
Definition Bio.cs:73

◆ TryParameterizeInteractiveRunCommand()

static bool BioLib.Fiji.TryParameterizeInteractiveRunCommand ( BioImage previewImage,
string con,
bool headless,
bool resultInNewTab,
out string parameterizedCommand )
static
708 {
709 parameterizedCommand = con;
710 if (previewImage == null || headless || !TryExtractBareRunCommand(con, out string commandName))
711 return false;
712
713 lock (imageJRunLock)
714 {
715 ImageJRecorder recorder = ImageJRecorder.getInstance();
716 bool createdRecorder = false;
717 bool previousRecordInMacros = ImageJRecorder.recordInMacros;
718 try
719 {
720 if (recorder == null)
721 {
722 recorder = new ImageJRecorder(false);
723 createdRecorder = recorder != null;
724 }
725
726 if (recorder == null)
727 return false;
728
729 ImageJRecorder.recordInMacros = true;
730 ImageJRecorder.resetCommandOptions();
731 string previousText = recorder.getText() ?? string.Empty;
732
733 cons = con;
734 indexs = 0;
735 Fiji.headless = headless;
736 resultInNewTabs = resultInNewTab;
737 bioImage = previewImage;
738 RunImageJ(false);
739
740 string recordedText = recorder.getText() ?? string.Empty;
741 if (TryExtractRecordedRunCommand(recordedText, previousText, commandName, out parameterizedCommand))
742 return true;
743
744 string options = ImageJRecorder.getCommandOptions() ?? string.Empty;
745 if (string.IsNullOrWhiteSpace(options))
746 return false;
747
748 parameterizedCommand = BuildRunCommand(commandName, options);
749 return true;
750 }
751 catch (Exception e)
752 {
753 Console.WriteLine($"[Fiji.TryParameterizeInteractiveRunCommand] {e.Message}");
754 parameterizedCommand = con;
755 return false;
756 }
757 finally
758 {
759 ImageJRecorder.resetCommandOptions();
760 ImageJRecorder.recordInMacros = previousRecordInMacros;
761 if (createdRecorder && recorder != null)
762 {
763 try
764 {
765 recorder.close();
766 }
767 catch
768 {
769 }
770 }
771 }
772 }
773 }
FijiNet::ij.plugin.frame.Recorder ImageJRecorder
Definition Fiji.cs:19

Member Data Documentation

◆ Macros

List<Macro.Command> BioLib.Fiji.Macros = new List<Macro.Command>()
static

◆ processes

List<Process> BioLib.Fiji.processes = new List<Process>()
static

Property Documentation

◆ ImageJMacroPath

string BioLib.Fiji.ImageJMacroPath
staticget
134 {
135 get
136 {
137 if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
138 {
139 string p = System.IO.Path.GetDirectoryName(ImageJPath).Replace("\\", "/");
140 p = p.Replace("/Fiji.app/Contents/MacOS/", "/Fiji.app/");
141 return p;
142 }
143 else
144 return System.IO.Path.GetDirectoryName(ImageJPath) + "/macros/";
145 }
146 }

◆ ImageJPath

string BioLib.Fiji.ImageJPath
staticgetset
123 {
124 get
125 {
126 return ijpath;
127 }
128 set
129 {
130 ijpath = value.Replace("\\","/");
131 }
132 }

◆ Initialized

bool BioLib.Fiji.Initialized
staticget
120{ get { return init; } private set { init = true; } }

◆ UseFiji

bool BioLib.Fiji.UseFiji
staticget
149 {
150 get
151 {
152 if(ImageJPath.Contains("Fiji"))
153 return true;
154 else
155 return false;
156 }
157 }

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