BioImager  5.0.0
A .NET microscopy imaging application based on Bio library. Supports various microscopes by using imported libraries & GUI automation. Supports XInput game controllers to move stage, take images, run ImageJ macros on images or Bio C# scripts.
Loading...
Searching...
No Matches
BioImager.ML.ML Class Reference

Classes

class  Model
 

Static Public Member Functions

static void Load (string mod)
 
static void Run (string modelsName, BioImage image)
 
static Bitmap ResizeBilinear (Bitmap original, int targetWidth, int targetHeight)
 
static void Initialize ()
 

Static Public Attributes

static List< Model > Models = new List<Model>()
 

Detailed Description

Definition at line 18 of file ML.cs.

Member Function Documentation

◆ Initialize()

static void BioImager.ML.ML.Initialize ( )
static

Definition at line 536 of file ML.cs.

537 {
538 string st = System.IO.Path.GetDirectoryName(Environment.ProcessPath);
539 Directory.CreateDirectory(st + "/Models");
540 foreach (string f in Directory.GetFiles(st + "/Models"))
541 {
542 if (f.EndsWith(".onnx") || f.EndsWith(".pt"))
543 {
544 string path = "Run/" + Path.GetFileName(f);
545 App.AddMenu(path);
546 }
547 }
548 }

◆ Load()

static void BioImager.ML.ML.Load ( string mod)
static

Definition at line 455 of file ML.cs.

456 {
457 Models.Add(new Model(mod));
458 }
static List< Model > Models
Definition ML.cs:454

◆ ResizeBilinear()

static Bitmap BioImager.ML.ML.ResizeBilinear ( Bitmap original,
int targetWidth,
int targetHeight )
static

Definition at line 484 of file ML.cs.

485 {
486 // Create a new Pixbuf with target dimensions
487 Bitmap resized = new Bitmap(targetWidth, targetHeight, original.PixelFormat);
488
489 int originalWidth = original.Width;
490 int originalHeight = original.Height;
491 float xRatio = originalWidth / (float)targetWidth;
492 float yRatio = originalHeight / (float)targetHeight;
493
494 // Lock the bits of the original and resized images (if necessary)
495
496 for (int y = 0; y < targetHeight; y++)
497 {
498 for (int x = 0; x < targetWidth; x++)
499 {
500 float gx = ((float)x) * xRatio;
501 float gy = ((float)y) * yRatio;
502 int gxi = (int)gx;
503 int gyi = (int)gy;
504
505 ColorS topLeft = original.GetPixel(gxi, gyi);
506 ColorS topRight = original.GetPixel(gxi + 1, gyi);
507 ColorS bottomLeft = original.GetPixel(gxi, gyi + 1);
508 ColorS bottomRight = original.GetPixel(gxi + 1, gyi + 1);
509
510 ushort red = (ushort)BilinearInterpolate(gx - gxi, gy - gyi, topLeft.R, topRight.R, bottomLeft.R, bottomRight.R);
511 ushort green = (ushort)BilinearInterpolate(gx - gxi, gy - gyi, topLeft.G, topRight.G, bottomLeft.G, bottomRight.G);
512 ushort blue = (ushort)BilinearInterpolate(gx - gxi, gy - gyi, topLeft.B, topRight.B, bottomLeft.B, bottomRight.B);
513
514 resized.SetPixel(x, y, new ColorS(red, green, blue));
515 }
516 }
517
518 // Unlock the bits (if necessary)
519
520 return resized;
521 }
AForge.Bitmap Bitmap

◆ Run()

static void BioImager.ML.ML.Run ( string modelsName,
BioImage image )
static

Definition at line 460 of file ML.cs.

461 {
462 string st = System.IO.Path.GetDirectoryName(Environment.ProcessPath) + "/Models/" + modelsName;
463 bool loaded = false;
464 foreach (var m in Models)
465 {
466 if (m.Name == Path.GetFileNameWithoutExtension(modelsName))
467 {
468 loaded = true;
469 break;
470 }
471 }
472 if (!loaded)
473 {
474 Models.Add(new Model(st));
475 }
476 foreach (var m in Models)
477 {
478 if (m.Name == Path.GetFileNameWithoutExtension(modelsName))
479 {
480 m.Run(image);
481 }
482 }
483 }

Member Data Documentation

◆ Models

List<Model> BioImager.ML.ML.Models = new List<Model>()
static

Definition at line 454 of file ML.cs.


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