BioGTK  6.0.0
A .NET library & program for annotating, editing various microscopy imaging formats using Bioformats supported images. Including whole slide, pyramidal, and series.
All Classes Namespaces Functions
BioGTK.SAMTool Class Reference
Inheritance diagram for BioGTK.SAMTool:

Public Member Functions

void Init (bool wait=false)
 

Static Public Member Functions

static SAMTool Create (bool micro_SAM)
 

Public Attributes

List< PromotionPromotions = new List<Promotion>()
 
bool init = false
 
MenuBar MainMenu
 

Static Public Attributes

static SAM sam
 
static MicroSAM microsam
 

Protected Member Functions

 SAMTool (Builder builder, IntPtr handle)
 
void SetupHandlers ()
 This function sets up the event handlers for the menu items.
 
void saveSelectedTiffClick (object sender, EventArgs a)
 

Properties

static bool microSAM [get]
 

Detailed Description

Definition at line 16 of file SAMTool.cs.

Constructor & Destructor Documentation

◆ SAMTool()

BioGTK.SAMTool.SAMTool ( Builder builder,
IntPtr handle )
protected

Definition at line 123 of file SAMTool.cs.

123 : base(handle)
124 {
125 //First lets make sure the model files are installed.
126 string app = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
127 if (microSAM)
128 {
129 if (!File.Exists(app + "/micro-sam-decoder.onnx") || !File.Exists(app + "/micro-sam-encoder.onnx"))
130 {
131 MessageDialog dialog = new MessageDialog(
132 this,
133 DialogFlags.Modal,
134 MessageType.Info,
135 ButtonsType.Ok,
136 "Place Model files \"micro-sam-decoder.onnx\" and \"micro-sam-encoder.onnx\" in the application folder to use SAM Tool.");
137 dialog.Run();
138 return;
139 }
140 }
141 else
142 {
143 if (!File.Exists(app + "/decoder-quant.onnx") || !File.Exists(app + "/encoder-quant.onnx"))
144 {
145 MessageDialog dialog = new MessageDialog(
146 this,
147 DialogFlags.Modal,
148 MessageType.Info,
149 ButtonsType.Ok,
150 "Place Model files \"decoder-quant.onnx\" and \"encoder-quant.onnx\" in the application folder to use SAM Tool.");
151 dialog.Run();
152 return;
153 }
154 }
155 view = App.viewer;
156 _builder = builder;
157 builder.Autoconnect(this);
158 thresholdBar.Adjustment.Lower = 0;
159 if (ImageView.SelectedImage.SelectedBuffer.BitsPerPixel > 8)
160 thresholdBar.Adjustment.Upper = ushort.MaxValue;
161 else
162 thresholdBar.Adjustment.Upper = 255;
163 stabilityBar.Adjustment.Lower = 0;
164 stabilityBar.Adjustment.Upper = 1;
165 stabilityBar.Adjustment.StepIncrement = 0.05;
166 stabilityBar.Value = 0.5;
167 predictionBar.Adjustment.Lower = 0;
168 predictionBar.Adjustment.Upper = 1;
169 predictionBar.Adjustment.StepIncrement = 0.05;
170 predictionBar.Value = 0.5;
171 pointsBar.Adjustment.Lower = 0;
172 pointsBar.Adjustment.Upper = 100;
173 pointsBar.Adjustment.StepIncrement = 1;
174 pointsBar.Value = 4;
175 layersBar.Adjustment.Lower = 0;
176 layersBar.Adjustment.Upper = 4;
177 layersBar.Value = 0;
178 minAreaBar.Value = 0;
179 minAreaBar.Adjustment.Upper = ImageView.SelectedImage.Volume.Width * ImageView.SelectedImage.Volume.Height;
180 minAreaBar.Adjustment.Lower = 0;
181
182 maxAreaBar.Adjustment.Upper = ImageView.SelectedImage.Volume.Width * ImageView.SelectedImage.Volume.Height;
183 maxAreaBar.Adjustment.Lower = 0;
184 maxAreaBar.Value = ImageView.SelectedImage.Volume.Width * ImageView.SelectedImage.Volume.Height;
185 foregroundBut.Active = true;
186 Directory.CreateDirectory("Masks");
187 filechooser =
188 new Gtk.FileChooserDialog("Choose file to open",
189 this,
190 FileChooserAction.Open,
191 "Cancel", ResponseType.Cancel,
192 "OK", ResponseType.Accept);
194 Init();
195 App.ApplyStyles(this);
196 init = true;
197 }
void Init(bool wait=false)
Definition SAMTool.cs:376
void SetupHandlers()
This function sets up the event handlers for the menu items.
Definition SAMTool.cs:204

Member Function Documentation

◆ Create()

static SAMTool BioGTK.SAMTool.Create ( bool micro_SAM)
static

It creates a new instance of the SAMTool class, which is a class that inherits from Gtk.Window

Returns
A new instance of the SAMTool class.

Definition at line 109 of file SAMTool.cs.

110 {
111 Builder builder = new Builder(new FileStream(System.IO.Path.GetDirectoryName(Environment.ProcessPath) + "/" + "Glade/SAM.glade", FileMode.Open));
112 if (micro_SAM)
113 {
114 sam = MicroSAM.Instance();
115 microsam = MicroSAM.Instance();
116 }
117 else
118 sam = SAM.Instance();
119 return new SAMTool(builder, builder.GetObject("SAMTool").Handle);
120 }
static new MicroSAM Instance()
Definition MicroSAM.cs:36
static SAM Instance()
Definition SAM.cs:33

◆ Init()

void BioGTK.SAMTool.Init ( bool wait = false)

The Init function loads an ONNX model, calculates image embedding, and updates the status accordingly.

Returns
If the condition ImageView.SelectedImage == null is true, then nothing is being returned and the method will exit. If the condition is false, then the method will continue executing the remaining code without returning anything.

Definition at line 376 of file SAMTool.cs.

377 {
378 if (ImageView.SelectedImage == null)
379 return;
380 if (MicroSAM.theSingleton == null)
381 {
382 sam.LoadONNXModel();
383 Thread th2 = new Thread(sam.Encode);
384 th2.Start();
385 }
386 else
387 {
388 microsam.LoadONNXModel();
389 Thread th2 = new Thread(microsam.Encode);
390 th2.Start();
391 }
392 do
393 {
394 Thread.Sleep(250);
395 if (microsam.Initialized)
396 break;
397 } while (wait);
398 BioLib.Recorder.AddLine("App.samTool.Init(true);",false);
399 }
new void LoadONNXModel()
The function LoadONNXModel loads ONNX models for encoding and decoding.
Definition MicroSAM.cs:46
void LoadONNXModel()
The function LoadONNXModel loads ONNX models for encoding and decoding.
Definition SAM.cs:43

◆ saveSelectedTiffClick()

void BioGTK.SAMTool.saveSelectedTiffClick ( object sender,
EventArgs a )
protected

It creates a file chooser dialog, and if the user selects a file, it saves the selected image to that file

Parameters
senderThe object that triggered the event.
EventArgsThis is the event that is being passed to the method.
Returns
The response type of the dialog.

Definition at line 488 of file SAMTool.cs.

489 {
490 filechooser.Action = FileChooserAction.Save;
491 //Saving Tiff can cause a crash on Windows so we check the platform.
492 if (Environment.OSVersion.Platform == PlatformID.Win32NT)
493 {
494 filechooser.Title = "Save File PNG";
495 }
496 else
497 {
498 filechooser.Title = "Save File Tiff";
499 }
500 if (filechooser.Run() != (int)ResponseType.Accept)
501 return;
502 if (Environment.OSVersion.Platform == PlatformID.Win32NT)
503 {
504 SelectedROI.roiMask.Pixbuf.Save(filechooser.Filename, "png");
505 }
506 else
507 {
508 SelectedROI.roiMask.Pixbuf.Save(filechooser.Filename, "tiff");
509 }
510 filechooser.Hide();
511 }

◆ SetupHandlers()

void BioGTK.SAMTool.SetupHandlers ( )
protected

This function sets up the event handlers for the menu items.

Definition at line 204 of file SAMTool.cs.

205 {
206 saveSelected.ButtonPressEvent += saveSelectedTiffClick;
207 view.ButtonReleaseEvent += PictureBox_ButtonReleaseEvent;
208 setAutoSave.ButtonPressEvent += SetAutoSave_ButtonPressEvent;
209 this.DeleteEvent += SAMTool_DeleteEvent;
210 textBox.Changed += TextBox_Changed;
211 toROIMenu.ButtonPressEvent += ToROIMenu_ButtonPressEvent;
212 runButton.ButtonPressEvent += AutoSAMMenu_ButtonPressEvent;
213 clearButton.ButtonPressEvent += ClearButton_ButtonPressEvent;
214 deleteDuplicatesBut.ButtonPressEvent += DeleteDuplicatesBut_ButtonPressEvent;
215 SAMEncodeBut.ButtonPressEvent += SAMEncodeBut_ButtonPressEvent;
216 clearSliceBut.ButtonPressEvent += ClearSliceBut_ButtonPressEvent;
217 }
void saveSelectedTiffClick(object sender, EventArgs a)
Definition SAMTool.cs:488

Member Data Documentation

◆ init

bool BioGTK.SAMTool.init = false

Definition at line 24 of file SAMTool.cs.

◆ MainMenu

MenuBar BioGTK.SAMTool.MainMenu

Definition at line 62 of file SAMTool.cs.

◆ microsam

MicroSAM BioGTK.SAMTool.microsam
static

Definition at line 22 of file SAMTool.cs.

◆ Promotions

List<Promotion> BioGTK.SAMTool.Promotions = new List<Promotion>()

Definition at line 23 of file SAMTool.cs.

◆ sam

SAM BioGTK.SAMTool.sam
static

Definition at line 21 of file SAMTool.cs.

Property Documentation

◆ microSAM

bool BioGTK.SAMTool.microSAM
staticget

Definition at line 25 of file SAMTool.cs.

26 {
27 get
28 {
29 if (microsam == null)
30 return false;
31 else
32 return true;
33 }
34 }

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