החלת מסנן הממוצע ומסנן וינר
החלת מסנן הממוצע ומסנן וינר
המסנן הממוצע הוא טכניקת סינון דיגיטלית לא לינארית, המשמשת להסרת רעש. הפחתה זו של רעש היא שלב טיפול טיפולי טיפולי טיפולי שטרודה רגיל הפובי לשפר את תוצאות הטיפול המאוחר. מסנן וינר הוא המסנן הלינארי המיטבי ביותר לשגיאת MSE (שגיאה מרובעת בממוצע) תוצאתי עבור תמונות עם רעש תוספי ושחזור. באמצעות Aspose.PSD עבור מפתחי API ג’אווה ניתן להחיל מסנן ממוצע על תמונה כדי להוריד את הרעש ולהחיל מסנן וינר של גאוס על תמונות. מאמר זה מדגים כיצד ניתן להחיל את מסנן הממוצע ואת מסנן וינר גאוס על תמונות.
החלת מסנן הממוצע
Aspose.PSD מספקת Class 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 מספקת Class 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 מספקת Class 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 מספקת Class 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 עבור ג’אווה כדי לבצע מסנני תיקון על תמונות. ממשקי ה-API של Aspose.PSD חשפו דרכים יעילות ונוחות לשימוש כדי להשיג מטרה זו. Aspose.PSD עבור ג’אווה חשפה Class BilateralSmoothingFilterOptions ו- SharpenFilterOptions לפילטרציה. נדרש ל Class BilateralSmoothingFilterOptions מספר שלם כגודל. הצעדים לביצוע שינוי גודל הם פשוטים ככל המידת הבאה:
- טען תמונה באמצעות השיטה המקיפה Load החשופה על ידי Image Class.
- המר את התמונה ל-RasterImage.
- צור מופעים של Class BilateralSmoothingFilterOptions ו- SharpenFilterOptions.
- קרא לשיטת Filter של RasterImage בזמן שמציין מלבן כגבולות התמונה ומופע Class BilateralSmoothingFilterOptions.
- קרא לשיטת Filter של RasterImage בזמן שמציין מלבן כגבולות התמונה ומופע Class 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"); | |
} |
שימוש באלגוריתם לחץ של בראדלי
הערת הגעת תמונה משמשת ביישומים גרפיים. המטרה של הערת תמונה היא לסווג פיקסלים כ “כהה” או “אור”. Aspose.PSD API מאפשר לך להשתמש בערת בראדלי בעת המרת תמונות. קטע הקוד הבא מראה לך כיצד להגדיר את ערך הסף ולהפעיל את אלגוריתם הערת בראדלי.
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()); | |
} |