การใช้งานตัวกรองมีเดียนและไวเนอร์

ตัวกรองมีเดียนเป็นเทคนิคการกรองดิจิทัลที่ไม่เชิงเส้น และมักถูกใช้เพื่อลดสัญญาณรบกวน เป็นขั้นตอนการประมวลผลก่อนที่จะส่งผลลัพธ์ให้กับการประมวลผลขั้นถัดไป ตัวกรองไวเนอร์เป็นตัวกรองเชิงเส้นแบบแปรผัน MSE (mean squared error) ที่ช่วยลดความเสียหายของภาพที่ถูกทำให้เสียสมด้วยสัญญานก๊ากเพิ่มขึ้นและภาพที่เบลอ เจลใช้ Aspose.PSD สำหรับนักพัฒนา API ของ Java สามารถใช้ตัวกรองมีเดียนเพื่อลดสัญญาณรบกวนในภาพ และสามารถใช้ตัวกรองไวเนอร์กาวที่อยู่บนภาพ บทความนี้สาธิตว่าตัวกรองมีเดียนและตัวกรองไวเนอร์กาวสามารถใช้บนภาพได้อย่างไร

การใช้งานตัวกรองมีเดียน

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 สำหรับ Java เพื่อทำตัวกรองการแก้ไขบนภาพ API ของ Aspose.PSD ได้เปิดเผยวิธีการใช้งานที่มีประสิทธิภาพและง่ายต่อการใช้งานเพื่อบรรลุวัตถุประสงค์นี้ Aspose.PSD สำหรับ Java ได้เปิดเผยคลาส BilateralSmoothingFilterOptions และ SharpenFilterOptions สำหรับการกรอง คลาส BilateralSmoothingFilterOptions จำเป็นต้องใช้เป็นจำนวนเต็ม เพื่อการกรองขั้นตอนการปรับขนาดจะง่ายดังด้านล่าง

  1. โหลดภาพโดยใช้เมทอดโรงงาน Load ที่เปิดเผยโดยคลาสภาพ.
  2. แปลงภาพเป็น RasterImage
  3. สร้างอินสแตนส์ของคลาส BilateralSmoothingFilterOptions และ SharpenFilterOptions
  4. เรียกเมทอดการกรองราสเตอร์ในขณะระบุสี่เหลี่ยมเป็นขอบภาพและอินสแตนส์คลาส BilateralSmoothingFilterOptions
  5. เรียกเมทอดการกรองราสเตอร์ในขณะระบุสี่เหลี่ยมเป็นขอบภาพและอินสแตนส์คลาส SharpenFilterOptions
  6. ปรับความคมชัน
  7. กำหนดความสว่าง
  8. บันทึกผลลัพธ์

โค้ดย่อด้านล่างแสดงวิธีการใช้ตัวกรองการแก้ข้อผิดพลาด

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 threshold algorithm

การกำหนดโปรแกรมระดับภาพถูกใช้ในแอพพลิเคชันกราฟิก วัตถุของการกำหนดขอบภาพคือการจำแนกพิกเซลเป็น “เข้ม” หรือ “สว่าง” Aspose.PSD API ช่วยให้คุณสามารถใช้ขั้นพอร์ต Bradley thresholding ขณะทำการแปลงภาพ โค้ดย่อต่อไปนี้จะแสดงให้เห็นวิธีการกำหนดค่าขีดจำกัดแล้วเรียกใช้อัลกอริทึมของ 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());
}