メディアンフィルターとWienerフィルターの適用
メディアンフィルターは非線形デジタルフィルタリング技術であり、ノイズを除去するためにしばしば使用されます。このようなノイズ低減は、後続の処理の結果を改善する典型的な前処理ステップです。Wienerフィルターは、加法ノイズとぼかしが加わった画像に対してMSE(平均二乗誤差)最適な静止線形フィルターです。Aspose.PSD for Java APIを使用すると、開発者は画像にメディアンフィルターを適用したり、画像にガウス・ウィーナーフィルターを適用したりできます。この記事では、画像にメディアンフィルターとガウス・ウィーナーフィルターを適用する方法を示します。
メディアンフィルターの適用
Aspose.PSDでは、MedianFilterOptionsクラスを提供して、RasterImageにフィルターを適用できます。以下に示すコードスニペットは、ラスター画像にメディアンフィルターを適用する方法を示しています。
String dataDir = Utils.getDataDir(ApplyMedianAndWienerFilters.class) + "Conversion/"; | |
String sourceFile = dataDir + "sample.psd"; | |
String destName = dataDir + "median_test_denoise_out.gif"; | |
try (Image image = Image.load(sourceFile); | |
// Cast the image into RasterImage | |
RasterImage rasterImage = (RasterImage) image) { | |
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.getBounds(), options); | |
image.save(destName, new GifOptions()); | |
} |
ガウス・ウィーナーフィルターの適用
Aspose.PSDでは、GaussWienerFilterOptionsクラスを提供して、RasterImageにフィルターを適用できます。以下に示すコードスニペットは、ラスター画像にガウス・ウィーナーフィルターを適用する方法を示しています。
String dataDir = Utils.getDataDir(ApplyGausWienerFilters.class) + "Conversion/"; | |
String sourceFile = dataDir + "sample.psd"; | |
String destName = dataDir + "gauss_wiener_out.gif"; | |
try (Image image = Image.load(sourceFile); | |
RasterImage rasterImage = (RasterImage) image) { | |
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.setGrayscale(true); | |
// Apply MedianFilterOptions filter to RasterImage object and Save the resultant image | |
rasterImage.filter(image.getBounds(), options); | |
image.save(destName, new GifOptions()); | |
} |
カラー画像にガウス・ウィーナーフィルターの適用
Aspose.PSDでは、カラー画像にもGaussWienerFilterOptionsを提供しています。以下に示すコードスニペットは、カラー画像にガウス・ウィーナーフィルターを適用する方法を示しています。
String dataDir = Utils.getDataDir(ApplyGausWienerFiltersForColorImage.class) + "Conversion/"; | |
String sourceFile = dataDir + "sample.psd"; | |
String destName = dataDir + "gauss_wiener_color_out.gif"; | |
try (Image image = Image.load(sourceFile); | |
// Cast the image into RasterImage | |
RasterImage rasterImage = (RasterImage) image) { | |
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.setBrightness(1); | |
// Apply MedianFilterOptions filter to RasterImage object and Save the resultant image | |
rasterImage.filter(image.getBounds(), options); | |
image.save(destName, new GifOptions()); | |
} |
モーション・ウィーナーフィルターの適用
Aspose.PSDでは、MotionWienerFilterOptionsクラスを提供して、RasterImageにフィルターを適用できます。以下に示すコードスニペットは、ラスター画像にモーション・ウィーナーフィルターを適用する方法を示しています。
String dataDir = Utils.getDataDir(ApplyMotionWienerFilters.class) + "Conversion/"; | |
String sourceFile = dataDir + "sample.psd"; | |
String destName = dataDir + "motion_filter_out.gif"; | |
try (Image image = Image.load(sourceFile); | |
// Cast the image into RasterImage | |
RasterImage rasterImage = (RasterImage) image) { | |
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.setGrayscale(true); | |
// Apply MedianFilterOptions filter to RasterImage object and Save the resultant image | |
rasterImage.filter(image.getBounds(), options); | |
image.save(destName, new GifOptions()); | |
} |
画像に補正フィルターを適用
この記事では、Aspose.PSD for Javaを使用して画像に補正フィルターを適用する方法を示します。Aspose.PSD APIでは、この目標を達成するために効率的で使いやすいメソッドが公開されています。Aspose.PSD for Javaでは、BilateralSmoothingFilterOptionsおよびSharpenFilterOptionsクラスがフィルトレーションのために公開されています。BilateralSmoothingFilterOptionsクラスはサイズを整数として必要とします。リサイズを実行する手順は以下のとおりです。
- Imageクラスが公開するLoadファクトリーメソッドを使用して画像を読み込みます。
- 画像をRasterImageに変換します。
- BilateralSmoothingFilterOptionsおよびSharpenFilterOptionsクラスのインスタンスを作成します。
- RasterImage.Filterメソッドを呼び出し、イメージ境界を指定し、BilateralSmoothingFilterOptionsクラスのインスタンスを指定します。
- RasterImage.Filterメソッドを呼び出し、イメージ境界を指定し、SharpenFilterOptionsクラスのインスタンスを指定します。
- コントラストを調整します。
- 明るさを設定します。
- 結果を保存します。
以下のコードスニペットは、補正フィルターを適用する方法を示しています。
try (Image image = Image.load(dataDir + "sample.psd"); | |
// Convert the image into RasterImage. | |
RasterImage rasterImage = (RasterImage) image) { | |
if (rasterImage == null) { | |
return; | |
} | |
// Get Bounds[rectangle] of image. | |
Rectangle rect = image.getBounds(); | |
// Create an instance of BilateralSmoothingFilterOptions class with size | |
// parameter. | |
BilateralSmoothingFilterOptions bilateralOptions = new BilateralSmoothingFilterOptions(3); | |
// Create an instance of SharpenFilterOptions class. | |
SharpenFilterOptions sharpenOptions = new SharpenFilterOptions(); | |
// Supply the filters to raster image. | |
rasterImage.filter(rect, bilateralOptions); | |
rasterImage.filter(rect, sharpenOptions); | |
// Adjust the contrast accordingly. | |
rasterImage.adjustContrast(-10); | |
// Set brightness using Binarize Bradley | |
rasterImage.binarizeBradley(80); | |
// Save the results to output path. | |
rasterImage.save(dataDir + "a1_out.jpg"); | |
} |
Bradley閾値アルゴリズムを使用
画像の閾値処理は、グラフィックアプリケーションで使用されます。画像の閾値処理の目的は、ピクセルを「暗い」と「明るい」のどちらかに分類することです。Aspose.PSD APIを使用すると、画像を変換する際にBradleyの閾値処理を使用することができます。以下のコードスニペットは、閾値値を定義し、Bradleyの閾値アルゴリズムを呼び出す方法を示しています。
String dataDir = Utils.getDataDir(Bradleythreshold.class) + "Conversion/"; | |
String sourceFile = dataDir + "sample.psd"; | |
String destName = dataDir + "binarized_out.png"; | |
// Load an image | |
try (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()); | |
} |