メディアンフィルタとワイナーフィルタの適用
メディアンフィルタとワイナーフィルタの適用
メディアンフィルタは非線形のデジタルフィルタリング手法であり、しばしばノイズを除去するために使用されます。このようなノイズ低減は通常、後続処理の結果を改善するための典型的な前処理手法です。ワイナーフィルタは、付加的なノイズとぼかしによって劣化した画像に対して、MSE(平均二乗誤差)最適な定常線形フィルタです。Aspose.PSDフィルターは.NET API開発者が画像にメディアンフィルタを適用し、画像にガウス・ワイナーフィルタを適用できるようにします。この記事では、メディアンフィルタとガウス・ワイナーフィルタの画像への適用方法を説明します。
メディアンフィルタの適用
Aspose.PSDは、MedianFilterOptionsクラスを提供して、RasterImageにフィルタを適用します。以下に示すコードスニペットでは、ラスター画像にメディアンフィルタを適用する方法が示されています。
// 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()); | |
} |
ガウス・ワイナーフィルタの適用
Aspose.PSDは、GaussWienerFilterOptionsクラスを提供して、RasterImageにフィルタを適用します。以下に示すコードスニペットでは、ラスター画像にガウス・ワイナーフィルタを適用する方法が示されています。
// 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()); | |
} |
カラー画像にガウス・ワイナーフィルタを適用する
Aspose.PSDは、カラー画像に対してもGaussWienerFilterOptionsを提供しています。以下に示すコードスニペットでは、カラー画像にガウス・ワイナーフィルタを適用する方法が示されています。
// 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()); | |
} |
モーション・ワイナーフィルタの適用
Aspose.PSDは、MotionWienerFilterOptions クラスを提供して、RasterImageにフィルタを適用します。以下に示すコードスニペットでは、ラスター画像にモーション・ワイナーフィルタを適用する方法が示されています。
// 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()); | |
} |