public void HilbertTests1() { int size0 = 1024; int size1 = 1024; var tuple = TestImageGenerator.GetTestPair2(size0, size1, 4, 15); HilbertPhaseImage2 hpi = new HilbertPhaseImage2(tuple.Item1, 0, 2 * Math.PI); hpi.Convert(); hpi.Calc(); hpi.Unwrapp(); hpi.ReverseConvert(); ImageSource.subtract_min(tuple.Item2); ImageSource.subtract_min(hpi.images[0]); double _min = ImageSource.min(tuple.Item2); double _max = ImageSource.max(tuple.Item2); double _mean = ImageSource.mean(tuple.Item2); double min = ImageSource.min(hpi.images[0]); double max = ImageSource.max(hpi.images[0]); double mean = ImageSource.mean(hpi.images[0]); double std = ImageSource.std(tuple.Item2, hpi.images[0]); Assert.IsTrue(std < ImageSource.mean(tuple.Item2) / 1000); }
private void button3_Click_2(object sender, EventArgs e) { var filePath = string.Empty; using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.InitialDirectory = Directory.Exists("c:\\") ? "c:\\images" : "c:\\"; openFileDialog.Filter = "Image Files(*.BMP;*.JPG;*.PNG)|*.BMP;*.JPG;*.PNG|All files (*.*)|*.*"; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { filePath = openFileDialog.FileName; bmp_ = new Bitmap(filePath); BitmapData bmd = bmp_.LockBits(new Rectangle(0, 0, bmp_.Width, bmp_.Height), ImageLockMode.ReadOnly, bmp_.PixelFormat); byte[] bytedata = new byte[bmp_.Height * bmp_.Width * 3]; IntPtr ptr = bmd.Scan0; Marshal.Copy(ptr, bytedata, 0, bmp_.Height * bmp_.Width * 3); image = new byte[bmp_.Height, bmp_.Width, 3]; IntPtr pointer = Marshal.UnsafeAddrOfPinnedArrayElement(image, 0); Marshal.Copy(bytedata, 0, pointer, bmp_.Height * bmp_.Width * 3); hpi2 = new HilbertPhaseImage2(image, (int)numericUpDown3.Value, settings != null? settings.wavelength:632.8, checkBox10.Checked) { calc = checkBox11.Checked, del_trend = checkBox9.Checked, smooth = checkBox8.Checked, delete_value = subtractiong_value }; pictureBox1.Image = new Bitmap(bmp_.Width, bmp_.Height, bmp_.Width * 3, PixelFormat.Format24bppRgb, pointer); pictureBox1.Update(); } } }
private void button1_Click(object sender, EventArgs e) { var tmp = TestImageGenerator.GetTestPair2(size0, size1, 5, 15); image0 = tmp.Item1; image_res = tmp.Item2; plot(image_res); hpi = new HilbertPhaseImage2(image0, 0, 1); }
public void PutImage(byte[,,] image, int level = 2, double wavelength = 632.8, bool unwrap = false, int summDepth = 0, bool smooth = false, bool calc = false, bool delTrend = false) { lock (locker) { HilbertPhaseImage2 hpi = new HilbertPhaseImage2(image, level, wavelength, unwrap, smooth) { summDepth = summDepth, calc = calc, del_trend = delTrend }; hpi.summDepth = summDepth; InputQueue.Enqueue(hpi); } }
private void execute() { set_defaults(); if (radioButton4.Checked) { int x = trackBar3.Value; int y = trackBar6.Value; int w = int.Parse(comboBox6.Text); int h = int.Parse(comboBox5.Text);; byte[,,] arr = new byte[h, w, 3]; for (int i = y; i < h + y; i++) { for (int j = x; j < w + x; j++) { arr[i - y, j - x, 0] = image[i, j, 0]; arr[i - y, j - x, 1] = image[i, j, 1]; arr[i - y, j - x, 2] = image[i, j, 2]; } } hpi2 = new HilbertPhaseImage2(arr, (int)numericUpDown3.Value, settings != null ? settings.wavelength : 632.8, checkBox10.Checked) { calc = checkBox11.Checked, del_trend = checkBox9.Checked, smooth = checkBox8.Checked, delete_value = subtractiong_value }; } else { hpi2 = new HilbertPhaseImage2(image, (int)numericUpDown3.Value, settings != null ? settings.wavelength : 632.8, checkBox10.Checked) { calc = checkBox11.Checked, del_trend = checkBox9.Checked, smooth = checkBox8.Checked, delete_value = subtractiong_value }; } hpi2.Convert(); hpi2.Calc(); hpi2.Unwrapp(); hpi2.ReverseConvert(); framing(); }
private void OnSnap(object sender, EventArgs e) { if (hpi2 != null) { HilbertPhaseImage2 temp = hpi2; Task.Factory.StartNew(() => { string folder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);; string folderPath = Path.Combine(folder, FolderPath); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } DateTime dt = DateTime.UtcNow; string path = Path.Combine(folderPath, dt.ToString().Replace('.', '_').Replace(':', '_').Replace(' ', '_')); path += dt.Millisecond.ToString(); Bitmap bmp = new Bitmap((int)temp.source_images[0].GetUpperBound(1) + 1, (int)temp.source_images[0].GetUpperBound(0) + 1, (int)(temp.source_images[0].GetUpperBound(1) + 1) * 3, PixelFormat.Format24bppRgb, Marshal.UnsafeAddrOfPinnedArrayElement(temp.source_images[0], 0)); bmp.Save(path + ".jpg"); temp.Save(path); }); } else { //if (toupcam_ != null) //{ // if (toupcam_.StillResolutionNumber <= 0) // { // if (bmp_ != null) // { // bmp_.Save(Path.Combine(richTextBox2.Text, "toupcamdemowinformcs2.jpg")); // } // } // else // { // if (button2.ContextMenuStrip != null) // button2.ContextMenuStrip.Show(Cursor.Position); // } //} } }
private void OnEventImage() { try { if (bmp_ != null) { if (this.tabControl1.SelectedIndex != 0) { return; } uint nWidth = 0, nHeight = 0; if (radioButton2.Checked) { byte[,,] arr = new byte[bmp_.Height, bmp_.Width, 3]; IntPtr pointer = Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0); toupcam_.PullImage(pointer, 24, out nWidth, out nHeight); int x = trackBar4.Value; int y = trackBar5.Value; int w = int.Parse(comboBox2.Text); int h = int.Parse(comboBox3.Text);; //Marshal.Copy(pointer, arr2, 0, arr.Length); for (int i = y; i < h + y; i++) { arr[i, x, 1] = 255; arr[i, x + 1, 1] = 255; arr[i, x + 2, 1] = 255; arr[i, x + w, 1] = 255; arr[i, x + w - 1, 1] = 255; arr[i, x + w - 2, 1] = 255; } for (int j = x; j < w + x; j++) { arr[y, j, 1] = 255; arr[y + 1, j, 1] = 255; arr[y + 2, j, 1] = 255; arr[y + h, j, 1] = 255; arr[y + h - 1, j, 1] = 255; arr[y + h - 2, j, 1] = 255; } pictureBox1.Image = new Bitmap((int)nWidth, (int)nHeight, (int)nWidth * 3, PixelFormat.Format24bppRgb, Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0)); pictureBox1.Update(); label5.Text = Math.Round(fPSCounter.Count(), 2).ToString(); label5.Update(); } else if (radioButton1.Checked) { if (checkBox4.Checked) { byte[,,] arr1 = new byte[bmp_.Height, bmp_.Width, 3]; IntPtr pointer = Marshal.UnsafeAddrOfPinnedArrayElement(arr1, 0); toupcam_.PullImage(pointer, 24, out nWidth, out nHeight); int x = trackBar4.Value; int y = trackBar5.Value; int w = int.Parse(comboBox2.Text); int h = int.Parse(comboBox3.Text);; byte[,,] arr = new byte[h, w, 3]; for (int i = y; i < h + y; i++) { for (int j = x; j < w + x; j++) { arr[i - y, j - x, 0] = arr1[i, j, 0]; arr[i - y, j - x, 1] = arr1[i, j, 1]; arr[i - y, j - x, 2] = arr1[i, j, 2]; } } //if (checkBox2.Checked) //{ calculator.PutImage(arr, level: (int)numericUpDown2.Value, unwrap: checkBox3.Checked, wavelength: settings.wavelength, smooth: checkBox5.Checked, summDepth: checkBox6.Checked ? (int)numericUpDown1.Value : 0, calc: checkBox2.Checked, delTrend: checkBox7.Checked); var buff = calculator.GetImage(); if (buff != null) { hpi2 = buff; } if (hpi2 != null) { arr = hpi2._images[0]; pictureBox1.Image = new Bitmap((int)w, (int)h, (int)w * 3, PixelFormat.Format24bppRgb, Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0)); pictureBox1.Update(); label5.Text = Math.Round(fPSCounter.Count(), 2).ToString(); label5.Update(); } //} //else //{ // pictureBox1.Image = new Bitmap((int)w, (int)h, (int)w * 3, PixelFormat.Format24bppRgb, // Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0)); // pictureBox1.Update(); // label5.Text = Math.Round(fPSCounter.Count(), 2).ToString(); // label5.Update(); //} } else { byte[,,] arr1 = new byte[bmp_.Height, bmp_.Width, 3]; IntPtr pointer = Marshal.UnsafeAddrOfPinnedArrayElement(arr1, 0); toupcam_.PullImage(pointer, 24, out nWidth, out nHeight); pictureBox1.Image = new Bitmap(bmp_.Width, bmp_.Height, bmp_.Width * 3, PixelFormat.Format24bppRgb, Marshal.UnsafeAddrOfPinnedArrayElement(arr1, 0)); pictureBox1.Update(); label5.Text = Math.Round(fPSCounter.Count(), 2).ToString(); label5.Update(); } } //button4_Click(null, null); } } catch { } }