/// <summary> /// 平滑化 /// </summary> private void CreateSmoothImage() { try { if (this.FileName == null) { this.FileName = this.SelectImageFile(); } CvSmoothType smoothType = this.SmoothProperty.SmoothType; int filterX = this.SmoothProperty.FilterX; int filterY = this.SmoothProperty.FilterY; double sigma1 = this.SmoothProperty.Sigma1; double sigma2 = this.SmoothProperty.Sigma2; using (CvImage orgImage = new CvImage(this.FileName)) using (CvImage smoothImage = CvImgProc.Smooth(orgImage, smoothType, filterX, filterY, sigma1, sigma2)) using (MemoryStream stream = new MemoryStream()) { Bitmap bitmap = smoothImage.GetImageBmp(); if (bitmap == null) { MessageBox.Show("bitmap null."); return; } bitmap.Save(stream, ImageFormat.Bmp); // BitmapImageの作成(キャッシュを切る) BitmapImage bmpImage = new BitmapImage(); bmpImage.BeginInit(); bmpImage.CacheOption = BitmapCacheOption.OnLoad; bmpImage.CreateOptions = BitmapCreateOptions.None; bmpImage.StreamSource = stream; bmpImage.EndInit(); bmpImage.Freeze(); this.Image006.Source = bmpImage; bmpImage = null; } } catch (Exception ex) { throw ex; } }
/// <summary> /// 適応型二値化 /// </summary> private void CreateAdaptBinaryImage() { try { if (this.FileName == null) { this.FileName = this.SelectImageFile(); } CvAdaptMethod adaptMethod = this.AdaptiveThresholdProperty.AdaptMethod; int blockSize = this.AdaptiveThresholdProperty.BlockSize; double param = this.AdaptiveThresholdProperty.Param; using (CvImage orgImage = new CvImage(this.FileName)) using (CvImage smoothImage = CvImgProc.AdaptiveThresdhold(orgImage, adaptMethod, blockSize, param)) using (MemoryStream stream = new MemoryStream()) { Bitmap bitmap = smoothImage.GetImageBmp(); if (bitmap == null) { MessageBox.Show("bitmap null."); return; } bitmap.Save(stream, ImageFormat.Bmp); // BitmapImageの作成(キャッシュを切る) BitmapImage bmpImage = new BitmapImage(); bmpImage.BeginInit(); bmpImage.CacheOption = BitmapCacheOption.OnLoad; bmpImage.CreateOptions = BitmapCreateOptions.None; bmpImage.StreamSource = stream; bmpImage.EndInit(); bmpImage.Freeze(); this.Image005.Source = bmpImage; bmpImage = null; } } catch (Exception ex) { throw ex; } }
/// <summary> /// 二値化 /// </summary> private void CreateBinaryImage() { try { if (this.FileName == null) { this.FileName = this.SelectImageFile(); } using (CvImage orgImage = new CvImage(this.FileName)) using (CvImage binImage = CvImgProc.Threshold(orgImage, this.Threshold)) using (MemoryStream stream = new MemoryStream()) { Bitmap bitmap = binImage.GetImageBmp(); if (bitmap == null) { MessageBox.Show("bitmap null."); return; } bitmap.Save(stream, ImageFormat.Bmp); // BitmapImageの作成(キャッシュを切る) BitmapImage bmpImage = new BitmapImage(); bmpImage.BeginInit(); bmpImage.CacheOption = BitmapCacheOption.OnLoad; bmpImage.CreateOptions = BitmapCreateOptions.None; bmpImage.StreamSource = stream; bmpImage.EndInit(); bmpImage.Freeze(); this.Image004.Source = bmpImage; bmpImage = null; } } catch (Exception ex) { throw ex; } finally { GC.Collect(); } }