BioImager  4.9.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
ChannelsTool.cs
1using AForge;
2using System;
3using System.Collections.Generic;
4using System.ComponentModel;
5using System.Drawing;
6using System.Drawing.Imaging;
7using System.Windows.Forms;
8namespace BioImager
9{
10 public partial class ChannelsTool : Form
11 {
12 private HistogramControl hist = null;
13 public List<Channel> Channels
14 {
15 get
16 {
17 return App.Channels;
18 }
19 }
20 /* A property that returns the selected channel from the channelsBox. */
21 public Channel SelectedChannel
22 {
23 get
24 {
25 if (channelsBox.SelectedIndex != -1)
26 return Channels[channelsBox.SelectedIndex];
27 else
28 return Channels[0];
29 }
30 }
31 /* A property that is used to get and set the value of the sampleBox.Value. */
32 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
33 public int SelectedSample
34 {
35 get
36 {
37 return (int)sampleBox.Value;
38 }
39 set
40 {
41 sampleBox.Value = (decimal)value;
42 }
43 }
45 public void UpdateItems()
46 {
47 channelsBox.Items.Clear();
48 foreach (Channel item in Channels)
49 {
50 channelsBox.Items.Add(item);
51 }
52 }
53 /* Creating a new instance of the ChannelsTool class. */
54 public ChannelsTool(List<Channel> Channels)
55 {
56 InitializeComponent();
57 foreach (Channel item in Channels)
58 {
59 channelsBox.Items.Add(item);
60 }
61 channelsBox.SelectedIndex = 0;
62 minBox.Value = (int)Channels[0].stats[0].StackMin;
63 maxBox.Value = (int)Channels[0].stats[0].StackMax;
64 hist = new HistogramControl(Channels[channelsBox.SelectedIndex]);
65 hist.GraphMax = (int)maxBox.Value;
66 maxGraphBox.Value = (int)maxBox.Value;
67 MouseWheel += new System.Windows.Forms.MouseEventHandler(ChannelsTool_MouseWheel);
68 statsPanel.Controls.Add(hist);
69 }
70
78 private void minBox_ValueChanged(object sender, EventArgs e)
79 {
80 if (channelsBox.SelectedIndex == -1)
81 return;
82 if (hist != null)
83 {
84 hist.UpdateChannel(Channels[channelsBox.SelectedIndex]);
85 hist.Invalidate();
86 hist.Min = (int)minBox.Value;
87 }
88 App.Channels[channelsBox.SelectedIndex].range[(int)sampleBox.Value].Min = (int)minBox.Value;
89 App.viewer.UpdateImage();
90 App.viewer.UpdateView();
91 }
99 private void maxBox_ValueChanged(object sender, EventArgs e)
100 {
101 if (channelsBox.SelectedIndex == -1)
102 return;
103 if (hist != null)
104 {
105 hist.UpdateChannel(Channels[channelsBox.SelectedIndex]);
106 hist.Invalidate();
107 hist.Max = (int)maxBox.Value;
108 }
109 App.Channels[channelsBox.SelectedIndex].range[(int)sampleBox.Value].Min = (int)minBox.Value;
110 App.viewer.UpdateImage();
111 App.viewer.UpdateView();
112 }
120 private void channelsBox_SelectedIndexChanged(object sender, EventArgs e)
121 {
122 if (channelsBox.SelectedIndex == -1)
123 return;
124 sampleBox.Value = 0;
125 sampleBox.Maximum = ((Channel)channelsBox.SelectedItem).range.Length - 1;
126 if (minBox.Maximum < Channels[channelsBox.SelectedIndex].range[(int)sampleBox.Value].Min || maxBox.Maximum < Channels[channelsBox.SelectedIndex].range[(int)sampleBox.Value].Max)
127 {
128 minBox.Value = 0;
129 maxBox.Value = ushort.MaxValue;
130 }
131 else
132 {
133 minBox.Value = Channels[channelsBox.SelectedIndex].range[(int)sampleBox.Value].Min;
134 maxBox.Value = Channels[channelsBox.SelectedIndex].range[(int)sampleBox.Value].Max;
135 }
136 if (hist != null)
137 {
138 //hist.Statistics = Channels[channelsBox.SelectedIndex].statistics;
139 hist.UpdateChannel(SelectedChannel);
140 hist.Invalidate();
141 }
142 fluorBox.Text = SelectedChannel.Fluor;
143 emisBox.Value = (decimal)SelectedChannel.Emission;
144 excBox.Value = (decimal)SelectedChannel.Excitation;
145 App.viewer.UpdateView();
146 }
152
153 private void maxUintBox_SelectedIndexChanged(object sender, EventArgs e)
154 {
155 int i = int.Parse((string)maxUintBox.SelectedItem,System.Globalization.CultureInfo.InvariantCulture);
156 if(i<=maxBox.Maximum)
157 maxBox.Value = i;
158
159 }
160
165 private void ChannelsTool_FormClosing(object sender, FormClosingEventArgs e)
166 {
167 e.Cancel = true;
168 this.Hide();
169 }
170
175 private void setMaxAllBut_Click(object sender, EventArgs e)
176 {
177 foreach (Channel c in Channels)
178 {
179 for (int i = 0; i < c.range.Length; i++)
180 {
181 c.range[i].Max = (int)maxBox.Value;
182 }
183 }
184 App.viewer.UpdateView();
185 }
186
191 private void setMinAllBut_Click(object sender, EventArgs e)
192 {
193 foreach (Channel c in Channels)
194 {
195 for (int i = 0; i < c.range.Length; i++)
196 {
197 c.range[i].Min = (int)minBox.Value;
198 }
199 }
200 App.viewer.UpdateView();
201 }
202
208 private void ChannelsTool_Activated(object sender, EventArgs e)
209 {
210 sampleBox.Maximum = SelectedChannel.SamplesPerPixel - 1;
211 for (int i = 0; i < SelectedChannel.range.Length; i++)
212 {
213 SelectedChannel.range[i].Min = (int)minBox.Value;
214 }
215 minBox.Value = SelectedChannel.range[(int)sampleBox.Value].Min;
216 maxBox.Value = SelectedChannel.range[(int)sampleBox.Value].Max;
217 UpdateItems();
218 hist.UpdateView();
219
220 }
221
226 private void ChannelsTool_ResizeEnd(object sender, EventArgs e)
227 {
228 hist.UpdateView();
229 }
230
236 private void maxUintBox2_SelectedIndexChanged(object sender, EventArgs e)
237 {
238 int i = int.Parse((string)maxUintBox2.SelectedItem, System.Globalization.CultureInfo.InvariantCulture);
239 if(i <= maxGraphBox.Maximum)
240 maxGraphBox.Value = i;
241 if (i == 255)
242 {
243 maxGraphBox.Value = 255;
244 binBox.Value = 1;
245 }
246 }
247
253 private void minGraphBox_ValueChanged(object sender, EventArgs e)
254 {
255 if (hist != null)
256 {
257 hist.GraphMin = (int)minGraphBox.Value;
258 hist.Invalidate();
259 }
260 }
261
267 private void maxGraphBox_ValueChanged(object sender, EventArgs e)
268 {
269 if (hist != null)
270 {
271 hist.GraphMax = (int)maxGraphBox.Value;
272 hist.Invalidate();
273 }
274 }
280 private void binBox_ValueChanged(object sender, EventArgs e)
281 {
282 if (hist != null)
283 {
284 hist.Bin = (int)binBox.Value;
285 hist.Invalidate();
286 }
287 }
288
293 private void ChannelsTool_MouseDown(object sender, MouseEventArgs e)
294 {
295
296 }
297 private bool pressedX1 = false;
298 private bool pressedX2 = false;
308 private void ChannelsTool_MouseMove(object sender, MouseEventArgs e)
309 {
310 if (e.Button == MouseButtons.XButton1)
311 {
312 if (channelsBox.SelectedIndex < channelsBox.Items.Count-1)
313 {
314 if (pressedX1 == false)
315 {
316 channelsBox.SelectedIndex++;
317 pressedX1 = true;
318 return;
319 }
320 }
321 }
322 pressedX1 = false;
323 if (e.Button == MouseButtons.XButton2)
324 {
325 if (channelsBox.SelectedIndex > 0)
326 {
327 if (pressedX2 == false)
328 {
329 channelsBox.SelectedIndex--;
330 pressedX2 = true;
331 return;
332 }
333 }
334 }
335 pressedX2 = false;
336 }
337
346 private void ChannelsTool_MouseWheel(object sender, MouseEventArgs e)
347 {
348 if (e.Delta == 0)
349 return;
350 int i = 100;
351 if (maxGraphBox.Value < 255)
352 i = 10;
353 if (e.Delta > 0)
354 {
355 if (maxGraphBox.Value + i < maxGraphBox.Maximum)
356 {
357 maxGraphBox.Value += i;
358 hist.Invalidate();
359 return;
360 }
361 }
362 else
363 if (maxGraphBox.Value - i > maxGraphBox.Minimum)
364 {
365 maxGraphBox.Value -= i;
366 hist.Invalidate();
367 return;
368 }
369 }
370
375 private void stackHistoBox_CheckedChanged(object sender, EventArgs e)
376 {
377 hist.StackHistogram = stackHistoBox.Checked;
378 hist.Invalidate();
379 }
380
386 private void setMinToolStripMenuItem_Click(object sender, EventArgs e)
387 {
388 minBox.Value = (int)hist.MouseValX;
389 }
390
396 private void setMaxToolStripMenuItem_Click(object sender, EventArgs e)
397 {
398 maxBox.Value = (int)hist.MouseValX;
399 }
400
406 private void applyBut_Click(object sender, EventArgs e)
407 {
408 ImageView.SelectedImage.Bake(ImageView.SelectedImage.RChannel.RangeR, ImageView.SelectedImage.GChannel.RangeG, ImageView.SelectedImage.BChannel.RangeB);
409 }
410
411 private void minToolStripMenuItem_Click(object sender, EventArgs e)
412 {
413 minBox.Value = (decimal)SelectedChannel.stats[channelsBox.SelectedIndex].StackMin;
414 }
415
416 private void maxToolStripMenuItem_Click(object sender, EventArgs e)
417 {
418 minBox.Value = (decimal)SelectedChannel.stats[channelsBox.SelectedIndex].StackMax;
419 }
420
421 private void medianToolStripMenuItem_Click(object sender, EventArgs e)
422 {
423 minBox.Value = (decimal)SelectedChannel.stats[channelsBox.SelectedIndex].StackMedian;
424 }
425
426 private void meanToolStripMenuItem_Click(object sender, EventArgs e)
427 {
428 minBox.Value = (decimal)SelectedChannel.stats[channelsBox.SelectedIndex].StackMean;
429 }
430
431 private void toolStripMenuItem1_Click(object sender, EventArgs e)
432 {
433 maxBox.Value = (decimal)SelectedChannel.stats[channelsBox.SelectedIndex].StackMin;
434 }
435
436 private void toolStripMenuItem2_Click(object sender, EventArgs e)
437 {
438 maxBox.Value = (decimal)SelectedChannel.stats[channelsBox.SelectedIndex].StackMax;
439 }
440 private void toolStripMenuItem3_Click(object sender, EventArgs e)
441 {
442 maxBox.Value = (decimal)SelectedChannel.stats[channelsBox.SelectedIndex].StackMedian;
443 }
444 private void toolStripMenuItem4_Click(object sender, EventArgs e)
445 {
446 maxBox.Value = (decimal)SelectedChannel.stats[channelsBox.SelectedIndex].StackMean;
447 }
448
453 private void updateBut_Click(object sender, EventArgs e)
454 {
455 if (ImageView.SelectedImage.bitsPerPixel > 8)
456 {
457 ImageView.SelectedImage.StackThreshold(true);
458 if (ImageView.SelectedImage.RGBChannelCount == 1)
459 {
460 maxBox.Value = (decimal)ImageView.SelectedImage.Channels[channelsBox.SelectedIndex].stats[0].StackMax;
461 minBox.Value = (decimal)ImageView.SelectedImage.Channels[channelsBox.SelectedIndex].stats[0].StackMin;
462 }
463 else
464 {
465 maxBox.Value = (decimal)ImageView.SelectedImage.Channels[channelsBox.SelectedIndex].stats[channelsBox.SelectedIndex].StackMax;
466 minBox.Value = (decimal)ImageView.SelectedImage.Channels[channelsBox.SelectedIndex].stats[channelsBox.SelectedIndex].StackMin;
467 }
468 }
469 else
470 {
471 ImageView.SelectedImage.StackThreshold(false);
472 }
473 App.viewer.UpdateImage();
474 }
475
481 private void sampleBox_ValueChanged(object sender, EventArgs e)
482 {
483 if (channelsBox.SelectedIndex == -1)
484 channelsBox.SelectedIndex = 0;
485 minBox.Value = Channels[channelsBox.SelectedIndex].range[(int)sampleBox.Value].Min;
486 maxBox.Value = Channels[channelsBox.SelectedIndex].range[(int)sampleBox.Value].Max;
487 if (hist != null)
488 {
489 //hist.Statistics = Channels[channelsBox.SelectedIndex].statistics;
490 hist.UpdateChannel(SelectedChannel);
491 hist.Invalidate();
492 }
493 App.viewer.UpdateView();
494 }
495
496 private void excBox_ValueChanged(object sender, EventArgs e)
497 {
498 SelectedChannel.Excitation = (int)excBox.Value;
499 }
500
501 private void emisBox_ValueChanged(object sender, EventArgs e)
502 {
503 SelectedChannel.Emission = (int)emisBox.Value;
504 }
505
506 private void fluorBox_TextChanged(object sender, EventArgs e)
507 {
508 SelectedChannel.Fluor = fluorBox.Text;
509 }
510 }
511}
void UpdateItems()
It clears the listbox and then adds all the items in the Channels list to the listbox.