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

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

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

การใช้งานฟิลเตอร์มีเดียน

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

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

ใช้วิธีการคำนวณของบรัดลีย์

การกำหนดค่าโค้งสะพรั่งใช้ในแอปพลิเคชันกราฟิก จุดมุ่งหลักของการกำหนดค่าโค้งในภาพคือการจำแนกพิกเซลเป็น “มืด” หรือ “สว่าง” Aspose.PSD API ช่วยให้คุณใช้วิธีการคำนวณบรัดลีย์ขณะที่แปลงภาพ ชิ้นส่วนโค้ดด้านล่างแสดงวิธีการกำหนดค่าค่าโค้งแล้วเรียกใช้วิธีการคำนวณบรัดลีย์

// 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());
}