Original: EMGU-WPF learning using-median blur
Implementation results:
Implementation path:
Premise: Image file-> system.drawing.bitmap->image<bgr, byte>
string sFile = GlobalVar.DATAS_PATH + "Samples/Test1.png"; BitmapImage oOriginBitSrc = new BitmapImage(new Uri(sFile));System.Drawing.Image oImgOrigin = System.Drawing.Image.FromFile(sFile);System.Drawing.Bitmap oBitmap = new System.Drawing.Bitmap(oImgOrigin);Image<Bgr, byte> imgSrc = new Image<Bgr, byte>(oBitmap);oBitmap.Dispose();
First line effect: Grayscale->otsu Two with the middle value blur--and Gaussian blur.
//中值模糊 Image<Bgr, byte> imgMedian = imgSrc.SmoothMedian(5); //使用5*5的卷积核 // 高斯模糊 Image<Bgr, byte> imgGaussian = imgMedian.SmoothGaussian(5); // 灰度化 Image<Gray, byte> imgGray = new Image<Gray, byte>(imgGaussian.Size); CvInvoke.CvtColor(imgGaussian, imgGray, ColorConversion.Bgr2Gray); // Otsu二值化 Image<Gray, byte> imgThresholdOtsu = new Image<Gray, byte>(imgGray.Size); CvInvoke.Threshold(imgGray, imgThresholdOtsu, 0, 255, ThresholdType.Otsu);
Second line effect: Grayscale->otsu Two-value blur with the original image
// 从原图直接灰度化Image<Gray, byte> imgOriginGray = new Image<Gray, byte>(imgSrc.Size);CvInvoke.CvtColor(imgSrc, imgOriginGray, ColorConversion.Bgr2Gray);// Otsu二值化Image<Gray, byte> imgOriginGrayThresholdOtsu = new Image<Gray, byte>(imgOriginGray.Size);CvInvoke.Threshold(imgOriginGray, imgOriginGrayThresholdOtsu, 0, 255, ThresholdType.Otsu);// 中值模糊Image<Gray, byte> imgMedian = imgOriginGrayThresholdOtsu.SmoothMedian(5);AppUtils.ShowGrayImage(this.ImgFun2Result3Zm, imgMedian);
Third line effect: original?-> grayscale?-> Gaussian fuzzy->otsu two value
?// 从原图直接灰度化Image<Gray, byte> imgOriginGray = new Image<Gray, byte>(imgSrc.Size);CvInvoke.CvtColor(imgSrc, imgOriginGray, ColorConversion.Bgr2Gray);// 高斯模糊Image<Gray, byte> imgGaussian = imgOriginGray.SmoothGaussian(5);// Otsu二值化Image<Gray, byte> imgOriginGrayThresholdOtsu = new Image<Gray, byte>(imgGaussian.Size);CvInvoke.Threshold(imgGaussian, imgOriginGrayThresholdOtsu, 0, 255, ThresholdType.Otsu);
Other: Transition to BitmapSource is rendered in the image of WPF.
[DllImport ("GDI32")] private static extern int DeleteObject (IntPtr o); <summary>//Convert an IImage to a WPF bitmapsource. The result can be used in the Set image.source//</summary>//<param name= "Image" &G T The EMGU CV image</param>///<returns>the equivalent bitmapsource</returns> public static BitmapSource Tobitmapsource (IImage image) {using (System.Drawing.Bitmap Source = image). Bitmap) {IntPtr ptr = source. Gethbitmap (); Obtain the hbitmap bitmapsource bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap ( PTR, IntPtr.Zero, Int32rect.empty, System.Windows.Me Dia. Imaging.BitmapSizeOptions.FromEmptyOptions ()); DeleteObject (PTR); Release the HBITMAP return BS; } }
To make it easier to see the gradual effects, I extracted the following methods.
public static void ShowImage(System.Windows.Controls.Image oImage, UMat src) { oImage.Dispatcher.Invoke(() => { oImage.Source = BitmapSourceConvert.ToBitmapSource(src); });}public static void ShowBgrImage(System.Windows.Controls.Image oImage, Image<Bgr, byte> src){ oImage.Dispatcher.Invoke(() => { oImage.Source = BitmapSourceConvert.ToBitmapSource(src); });}public static void ShowGrayImage(System.Windows.Controls.Image oImage, Image<Gray, byte> src){ oImage.Dispatcher.Invoke(() => { oImage.Source = BitmapSourceConvert.ToBitmapSource(src); });}
I refer to the link: Click the open link? https://www.cnblogs.com/CoverCat/p/5055644.html
??????????????????? http://www.cnblogs.com/CoverCat/p/5043833.html?
EMGU-WPF Learning using-median blur