1using AForge.Imaging.Filters;
3using AForge.Math.Geometry;
7using System.Collections.Generic;
8using System.ComponentModel;
13using System.Threading.Tasks;
14using System.Windows.Forms;
21 List<Blob> blobs =
new List<Blob>();
22 List<BioImage> images =
new List<BioImage>();
24 System.Drawing.Bitmap bitmap;
27 InitializeComponent();
29 viewer.ShowControls =
false;
30 imageSplitContainer.Panel2.Controls.Add(viewer);
33 objectivesBox.Items.Add(item.Name);
36 maxWidthLabel.Text =
"Max Width:" + maxWidthBar.Value;
37 maxHeightLabel.Text =
"Max Height:" + maxHeightBar.Value;
38 minHeightLabel.Text =
"Min Height:" + minHeightBar.Value;
39 minWidthLabel.Text =
"Min Width:" + minWidthBar.Value;
42 comboBox.Items.Add(item);
46 private void maxWidthBar_Scroll(
object sender, EventArgs e)
48 maxWidthLabel.Text =
"Max Width:" + maxWidthBar.Value;
51 private void maxHeightBar_Scroll(
object sender, EventArgs e)
53 maxHeightLabel.Text =
"Max Height:" + maxHeightBar.Value;
56 private void minHeightBar_Scroll(
object sender, EventArgs e)
58 minHeightLabel.Text =
"Min Height:" + minHeightBar.Value;
61 private void sizeBar_Scroll(
object sender, EventArgs e)
63 minWidthLabel.Text =
"Min Width:" + minWidthBar.Value;
66 private void thresholdBar_Scroll(
object sender, EventArgs e)
68 thresholdLabel.Text =
"Threshold:" + thresholdBar.Value;
73 private void helpToolStripMenuItem_Click(
object sender, EventArgs e)
75 MessageBox.Show(
"Cell Imager allows for performing imaging routines on individual cells based on blob detection." +
76 " Set threshold and size range for detection. Also allows for an imaging script to be run on each cell.");
79 private void detectBut_Click(
object sender, EventArgs e)
82 bitmap =
new System.Drawing.Bitmap(b.SizeX, b.SizeY);
84 Statistics[] sts = Statistics.FromBytes(b.Buffers[0]);
85 Statistics st = sts[0];
87 if (numericRBut.Checked)
89 th =
new Threshold(thresholdBar.Value);
92 th =
new Threshold((
int)(st.Median));
93 AForge.Bitmap bf = b.GetBitmap(0, (
int)chanBox.Value - 1, 0);
94 if (bf.RGBChannelsCount > 1)
96 ExtractChannel ch =
new ExtractChannel((
short)(rgbBox.Value - 1));
100 Invert inv =
new Invert();
101 inv.ApplyInPlace(bf);
103 if (bf.BitsPerPixel > 8)
104 det = AForge.Imaging.Image.Convert16bppTo8bpp(bf);
107 pictureBox.Image =
new System.Drawing.Bitmap(det.Width, det.Height, det.Width * 4, System.Drawing.Imaging.PixelFormat.Format32bppArgb, det.GetRGBData());
108 BlobCounter blobCounter =
new BlobCounter();
109 blobCounter.ProcessImage(det);
110 Blob[] bls = blobCounter.GetObjectsInformation();
112 foreach (Blob blob
in bls)
114 if (blob.Rectangle.Width < minWidthBar.Value || blob.Rectangle.Height < minHeightBar.Value || blob.Rectangle.Width > maxWidthBar.Value || blob.Rectangle.Height > maxHeightBar.Value)
121 private void UpdateItems()
124 foreach (Blob blob
in blobs)
126 ListViewItem item =
new ListViewItem(blob.Rectangle.Width +
"," + blob.Rectangle.Height);
128 listView.Items.Add(item);
136 foreach (Blob blob
in blobs)
138 if (blob.Rectangle.Width < minWidthBar.Value || blob.Rectangle.Height < minHeightBar.Value || blob.Rectangle.Width > maxWidthBar.Value || blob.Rectangle.Height > maxHeightBar.Value)
140 PointD loc =
new PointD(b.StageSizeX + (blob.Rectangle.X * b.PhysicalSizeX), b.StageSizeY + (blob.Rectangle.Y * b.PhysicalSizeY));
145 for (
int y = 0; y < tileYBox.Value; y++)
147 for (
int x = 0; x < tileXBox.Value; x++)
149 if (comboBox.SelectedIndex != -1)
158 if (comboBox.SelectedIndex != -1)
167 viewer.
Images.AddRange(images);
171 private void clearBut_Click(
object sender, EventArgs e)
176 private void pictureBox_Paint(
object sender, PaintEventArgs e)
180 System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
182 Pen bb =
new Pen(Brushes.Blue, 2);
183 Pen r =
new Pen(Brushes.Red, 2);
184 foreach (Blob b
in blobs)
186 if (listView.Items[i].Selected)
187 g.DrawRectangle(bb,
new System.Drawing.Rectangle(b.Rectangle.X, b.Rectangle.Y, b.Rectangle.Width, b.Rectangle.Height));
189 g.DrawRectangle(r,
new System.Drawing.Rectangle(b.Rectangle.X, b.Rectangle.Y, b.Rectangle.Width, b.Rectangle.Height));
195 e.Graphics.DrawImage(bitmap, 0, 0, pictureBox.Width, pictureBox.Height);
198 private void imageAllBut_Click(
object sender, EventArgs e)
200 Image(blobs.ToArray());
203 private void imageCurBut_Click(
object sender, EventArgs e)
205 List<Blob> blobs =
new List<Blob>();
206 foreach (ListViewItem blob
in listView.Items)
209 blobs.Add((Blob)blob.Tag);
211 Image(blobs.ToArray());
214 private void listView_SelectedIndexChanged(
object sender, EventArgs e)
216 pictureBox.Invalidate();
219 private void CellImager_FormClosing(
object sender, FormClosingEventArgs e)
System.Drawing.Image Image
ImageView control for image stacks, pyramidal and whole-slide-images.
void UpdateView(bool refreshImages=true)
static Objectives Objectives
static BioImage[] TakeTiles(int width, int height, bool save=true, bool addToImages=true, bool newTab=false)
static void SetPosition(Point3D p)
static Point3D GetPosition()
static BioImage TakeImage()
void SetPosition(int index)
static Dictionary< string, Script > Scripts