应用中值和Wiener滤波器
应用中值和Wiener滤波器
中值滤波是一种非线性数字滤波技术,通常用于去除噪声。这种噪声减少是一种典型的预处理步骤,旨在改善后续处理的结果。Wiener滤波器是用于添加噪声和模糊的图像的均方误差(MSE)最优静态线性滤波器。使用Aspose.PSD for .NET API,开发人员可以将中值滤波器应用于去噪图像,并可以对图像应用高斯Wiener滤波器。本文演示了如何将中值滤波器和高斯Wiener滤波器应用于图像。
应用中值滤波器
Aspose.PSD提供MedianFilterOptions类,用于在光栅图像上应用滤波器。下面提供的代码片段演示了如何将中值滤波器应用于光栅图像。
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"median_test_denoise_out.gif"; | |
// Load the noisy image | |
using (Image image = Image.Load(sourceFile)) | |
{ | |
// Cast the image into RasterImage | |
RasterImage rasterImage = image as RasterImage; | |
if (rasterImage == null) | |
{ | |
return; | |
} | |
// Create an instance of MedianFilterOptions class and set the size, Apply MedianFilterOptions filter to RasterImage object and Save the resultant image | |
MedianFilterOptions options = new MedianFilterOptions(4); | |
rasterImage.Filter(image.Bounds, options); | |
image.Save(destName, new GifOptions()); | |
} |
应用高斯Wiener滤波器
Aspose.PSD提供GaussWienerFilterOptions类,用于在光栅图像上应用滤波器。下面提供的代码片段演示了如何将高斯Wiener滤波器应用于光栅图像。
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"gauss_wiener_out.gif"; | |
// Load the noisy image | |
using (Image image = Image.Load(sourceFile)) | |
{ | |
RasterImage rasterImage = image as RasterImage; | |
if (rasterImage == null) | |
{ | |
return; | |
} | |
// Create an instance of GaussWienerFilterOptions class and set the radius size and smooth value. | |
GaussWienerFilterOptions options = new GaussWienerFilterOptions(12, 3); | |
options.Grayscale = true; | |
// Apply MedianFilterOptions filter to RasterImage object and Save the resultant image | |
rasterImage.Filter(image.Bounds, options); | |
image.Save(destName, new GifOptions()); | |
} |
应用彩色图像的高斯Wiener滤波器
Aspose.PSD还为彩色图像提供了GaussWienerFilterOptions,下面提供的代码片段演示了如何将高斯Wiener滤波器应用于彩色图像。
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"gauss_wiener_color_out.gif"; | |
// Load the noisy image | |
using (Image image = Image.Load(sourceFile)) | |
{ | |
// Cast the image into RasterImage | |
RasterImage rasterImage = image as RasterImage; | |
if (rasterImage == null) | |
{ | |
return; | |
} | |
// Create an instance of GaussWienerFilterOptions class and set the radius size and smooth value. | |
GaussWienerFilterOptions options = new GaussWienerFilterOptions(5, 1.5); | |
options.Brightness = 1; | |
// Apply MedianFilterOptions filter to RasterImage object and Save the resultant image | |
rasterImage.Filter(image.Bounds, options); | |
image.Save(destName, new GifOptions()); | |
} |
应用运动Wiener滤波器
Aspose.PSD提供MotionWienerFilterOptions 类,用于在光栅图像上应用滤波器。下面提供的代码片段演示了如何将运动Wiener滤波器应用于光栅图像。
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"motion_filter_out.gif"; | |
// Load the noisy image | |
using (Image image = Image.Load(sourceFile)) | |
{ | |
// Cast the image into RasterImage | |
RasterImage rasterImage = image as RasterImage; | |
if (rasterImage == null) | |
{ | |
return; | |
} | |
// Create an instance of MotionWienerFilterOptions class and set the length, smooth value and angle. | |
MotionWienerFilterOptions options = new MotionWienerFilterOptions(50, 9, 90); | |
options.Grayscale = true; | |
// Apply MedianFilterOptions filter to RasterImage object and Save the resultant image | |
rasterImage.Filter(image.Bounds, options); | |
image.Save(destName, new GifOptions()); | |
} |
在图像上应用校正滤波器
本文演示了使用Aspose.PSD for .NET对图像执行校正滤波器的用法。 Aspose.PSD API公开了高效且易于使用的方法,以实现此目标。 Aspose.PSD for .NET已公开了BilateralSmoothingFilterOptions 和SharpenFilterOptions 类以用于过滤。 BilateralSmoothingFilterOptions类需要一个整数作为大小。 执行调整的步骤如下:
- 使用Image类公开的工厂方法Load加载图像。
- 将图像转换为RasterImage。
- 创建BilateralSmoothingFilterOptions和SharpenFilterOptions类的实例。
- 调用RasterImage.Filter方法,同时指定矩形作为图像边界和BilateralSmoothingFilterOptions类的实例。
- 调用RasterImage.Filter方法,同时指定矩形作为图像边界和SharpenFilterOptions类的实例。
- 调整对比度
- 设置亮度
- 保存结果。
使用Bradley阈值算法
图像阈值在图形应用中使用。图像阈值的目标是将像素分类为“暗”或“亮”。 Aspose.PSD API允许您在转换图像时使用Bradley阈值。以下代码片段显示了如何定义阈值,并调用Bradley的阈值算法。
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"binarized_out.png"; | |
// Load the noisy image | |
// Load an image | |
using (PsdImage image = (PsdImage)Image.Load(sourceFile)) | |
{ | |
// Define threshold value, Call BinarizeBradley method and pass the threshold value as parameter and Save the output image | |
double threshold = 0.15; | |
image.BinarizeBradley(threshold); | |
image.Save(destName, new PngOptions()); | |
} |