Professional image processing filters and effects.
// Gaussian blur
blurred := advancegg.ApplyGaussianBlur(img, 5.0) // 5 pixel radius
// Box blur (faster)
boxBlurred := advancegg.ApplyBoxBlur(img, 3)
// Motion blur
motionBlurred := advancegg.ApplyMotionBlur(img, 10, 45) // 10px distance, 45° angle
// Radial blur
radialBlurred := advancegg.ApplyRadialBlur(img, centerX, centerY, 8)
// Zoom blur
zoomBlurred := advancegg.ApplyZoomBlur(img, centerX, centerY, 0.1) // 10% zoom
// Surface blur (edge-preserving)
surfaceBlurred := advancegg.ApplySurfaceBlur(img, 5, 15) // radius, threshold
// Unsharp mask
sharpened := advancegg.ApplyUnsharpMask(img, 1.5, 1.0, 0) // amount, radius, threshold
// Simple sharpen
sharpened := advancegg.ApplySharpen(img, 0.5) // strength
// Smart sharpen
smartSharpened := advancegg.ApplySmartSharpen(img, 2.0, 1.0, true) // amount, radius, reduce noise
// High pass filter
highPass := advancegg.ApplyHighPass(img, 3.0) // radius
// Add noise
noisy := advancegg.AddNoise(img, 0.1, advancegg.NoiseTypeGaussian)
noisy := advancegg.AddNoise(img, 0.05, advancegg.NoiseTypeUniform)
noisy := advancegg.AddNoise(img, 0.08, advancegg.NoiseTypeSaltPepper)
// Remove noise
denoised := advancegg.ApplyMedianFilter(img, 3) // 3x3 kernel
denoised := advancegg.ApplyBilateralFilter(img, 9, 75, 75) // d, sigmaColor, sigmaSpace
denoised := advancegg.ApplyNonLocalMeansDenoising(img, 10, 7, 21) // h, templateWindowSize, searchWindowSize
// Dust and scratches
cleaned := advancegg.RemoveDustAndScratches(img, 2, 50) // radius, threshold
// Brightness and contrast
bright := advancegg.ApplyBrightness(img, 1.2) // 20% brighter
contrast := advancegg.ApplyContrast(img, 1.5) // 50% more contrast
combined := advancegg.ApplyBrightnessContrast(img, 1.1, 1.3)
// Gamma correction
gamma := advancegg.ApplyGamma(img, 1.4)
// Exposure
exposed := advancegg.ApplyExposure(img, 0.5) // +0.5 stops
// Levels adjustment
leveled := advancegg.ApplyLevels(img, 0, 1, 0.5, 0, 255) // input min/max, gamma, output min/max
// Hue, saturation, lightness
hsl := advancegg.ApplyHSL(img, 15, 1.2, 1.1) // +15° hue, +20% saturation, +10% lightness
// Color balance
balanced := advancegg.ApplyColorBalance(img, -10, 5, 15) // cyan-red, magenta-green, yellow-blue
// Vibrance and saturation
vibrant := advancegg.ApplyVibrance(img, 0.3) // Selective saturation
saturated := advancegg.ApplySaturation(img, 1.4) // Overall saturation
// Temperature and tint
warmed := advancegg.ApplyTemperature(img, 200) // Warmer (+200K)
tinted := advancegg.ApplyTint(img, -10) // Magenta tint
// Grayscale conversions
gray := advancegg.ApplyGrayscale(img)
grayLuminance := advancegg.ApplyGrayscaleLuminance(img)
grayDesaturate := advancegg.ApplyGrayscaleDesaturate(img)
// Sepia tone
sepia := advancegg.ApplySepia(img, 0.8) // intensity
// Color tinting
tinted := advancegg.ApplyColorTint(img, color.RGBA{255, 200, 100, 128})
// Duotone
duotone := advancegg.ApplyDuotone(img,
color.RGBA{50, 50, 100, 255}, // Shadow color
color.RGBA{255, 200, 150, 255}) // Highlight color
// Posterize
posterized := advancegg.ApplyPosterize(img, 8) // 8 levels per channel
// Threshold
threshold := advancegg.ApplyThreshold(img, 128) // Binary threshold at 128
// Oil painting
oilPainting := advancegg.ApplyOilPainting(img, 5, 20) // brush size, intensity
// Watercolor
watercolor := advancegg.ApplyWatercolor(img, 0.8, 0.6) // wetness, bleeding
// Acrylic painting
acrylic := advancegg.ApplyAcrylicPainting(img, 3, 15) // brush size, detail
// Impressionist
impressionist := advancegg.ApplyImpressionist(img, 4, 8) // brush size, variation
// Pointillism
pointillism := advancegg.ApplyPointillism(img, 3, 0.7) // dot size, coverage
// Pencil sketch
pencil := advancegg.ApplyPencilSketch(img, 0.1, 0.15) // detail, shading
// Charcoal drawing
charcoal := advancegg.ApplyCharcoal(img, 2, 0.8) // stroke size, intensity
// Ink drawing
ink := advancegg.ApplyInkDrawing(img, 3, 0.5) // line weight, detail
// Cross hatch
crossHatch := advancegg.ApplyCrossHatch(img, 2, 45) // line spacing, angle
// Stippling
stippling := advancegg.ApplyStippling(img, 1.5, 0.6) // dot size, density
// Cartoon effect
cartoon := advancegg.ApplyCartoon(img, 7, 200, 20) // blur, edge threshold, edge amount
// Comic book
comic := advancegg.ApplyComicBook(img, 4, 80) // color reduction, edge strength
// Pop art
popArt := advancegg.ApplyPopArt(img, 6, 4) // colors, contrast
// Mosaic
mosaic := advancegg.ApplyMosaic(img, 8) // tile size
// Stained glass
stainedGlass := advancegg.ApplyStainedGlass(img, 12, 3) // cell size, border width
// Emboss
embossed := advancegg.ApplyEmboss(img, 45, 3) // angle, depth
// Sobel edge detection
sobelEdges := advancegg.ApplySobelEdgeDetection(img)
// Canny edge detection
cannyEdges := advancegg.ApplyCannyEdgeDetection(img, 50, 150) // low, high threshold
// Laplacian edge detection
laplacianEdges := advancegg.ApplyLaplacianEdgeDetection(img)
// Prewitt edge detection
prewittEdges := advancegg.ApplyPrewittEdgeDetection(img)
// Roberts cross-gradient
robertsEdges := advancegg.ApplyRobertsEdgeDetection(img)
// Scharr edge detection
scharrEdges := advancegg.ApplySchurrEdgeDetection(img)
// Find edges
edges := advancegg.FindEdges(img, 0.1) // threshold
// Enhance edges
enhanced := advancegg.EnhanceEdges(img, 2.0) // strength
// Edge-preserving smoothing
smoothed := advancegg.ApplyEdgePreservingSmoothing(img, 50, 0.4) // flags, sigma
// Anisotropic diffusion
diffused := advancegg.ApplyAnisotropicDiffusion(img, 0.1, 20, 30) // kappa, gamma, iterations
// Barrel distortion
barrel := advancegg.ApplyBarrelDistortion(img, 0.2) // strength
// Pincushion distortion
pincushion := advancegg.ApplyPincushionDistortion(img, 0.15)
// Fisheye effect
fisheye := advancegg.ApplyFisheye(img, 1.5) // strength
// Spherize
spherized := advancegg.ApplySpherize(img, 0.8, advancegg.SpherizeNormal)
// Twirl
twirled := advancegg.ApplyTwirl(img, centerX, centerY, 45, 100) // angle, radius
// Ripple
rippled := advancegg.ApplyRipple(img, 10, 20, advancegg.RippleTypeSine) // amplitude, wavelength
// Wave distortion
waved := advancegg.ApplyWave(img, 20, 50, 0, advancegg.WaveTypeSine) // amplitude, wavelength, phase
// Displacement map
displacementMap := advancegg.LoadImage("displacement.png")
displaced := advancegg.ApplyDisplacement(img, displacementMap, 10, 10) // x scale, y scale
// Liquify
liquified := advancegg.ApplyLiquify(img, points, radius, strength) // control points
// Polar coordinates
polar := advancegg.ApplyPolarCoordinates(img, advancegg.PolarRectangularToPolar)
rectangular := advancegg.ApplyPolarCoordinates(img, advancegg.PolarPolarToRectangular)
// Create filter chain
chain := advancegg.NewFilterChain()
// Add filters to chain
chain.AddFilter(advancegg.NewGaussianBlurFilter(2.0))
chain.AddFilter(advancegg.NewBrightnessFilter(1.1))
chain.AddFilter(advancegg.NewContrastFilter(1.2))
chain.AddFilter(advancegg.NewSaturationFilter(1.15))
// Apply chain
result := chain.Apply(img)
// Chain with conditions
conditionalChain := advancegg.NewFilterChain()
conditionalChain.AddFilterIf(advancegg.NewNoiseReductionFilter(0.1), func(img image.Image) bool {
return advancegg.DetectNoise(img) > 0.05 // Only if noisy
})
// Parallel processing
parallelChain := advancegg.NewParallelFilterChain()
parallelChain.AddFilter(advancegg.NewSharpenFilter(0.5))
parallelChain.AddFilter(advancegg.NewColorBalanceFilter(-5, 0, 5))
result := parallelChain.Apply(img)
// Create adjustment layer
adjustmentLayer := advancegg.NewAdjustmentLayer(img)
// Add adjustments
adjustmentLayer.AddAdjustment(advancegg.NewBrightnessAdjustment(1.1))
adjustmentLayer.AddAdjustment(advancegg.NewContrastAdjustment(1.2))
adjustmentLayer.AddAdjustment(advancegg.NewHueSaturationAdjustment(5, 1.15, 0))
// Apply adjustments
result := adjustmentLayer.Render()
// Modify adjustments
adjustmentLayer.ModifyAdjustment(0, advancegg.NewBrightnessAdjustment(1.05)) // Change brightness
adjustmentLayer.RemoveAdjustment(1) // Remove contrast
// Save adjustment preset
preset := adjustmentLayer.SavePreset()
advancegg.SavePresetToFile(preset, "my-preset.json")
// Load and apply preset
loadedPreset := advancegg.LoadPresetFromFile("my-preset.json")
newAdjustmentLayer := advancegg.NewAdjustmentLayerFromPreset(img, loadedPreset)
// Define custom kernel
kernel := [][]float64{
{-1, -1, -1},
{-1, 8, -1},
{-1, -1, -1},
} // Edge detection kernel
// Apply custom kernel
filtered := advancegg.ApplyKernel(img, kernel, 1.0, 0) // divisor, offset
// Separable kernel (more efficient)
horizontalKernel := []float64{1, 2, 1}
verticalKernel := []float64{1, 2, 1}
separableFiltered := advancegg.ApplySeparableKernel(img, horizontalKernel, verticalKernel)
// Morphological operations
eroded := advancegg.ApplyErosion(img, 3) // 3x3 kernel
dilated := advancegg.ApplyDilation(img, 3)
opened := advancegg.ApplyOpening(img, 3) // Erosion followed by dilation
closed := advancegg.ApplyClosing(img, 3) // Dilation followed by erosion
// Custom pixel function
customFilter := func(r, g, b, a uint8) (uint8, uint8, uint8, uint8) {
// Custom processing logic
newR := uint8(float64(r) * 1.2)
newG := uint8(float64(g) * 0.8)
newB := uint8(float64(b) * 1.1)
return newR, newG, newB, a
}
// Apply pixel function
result := advancegg.ApplyPixelFunction(img, customFilter)
// Neighborhood function (access surrounding pixels)
neighborhoodFilter := func(pixels [][]color.Color, x, y int) color.Color {
// Access pixels[y][x] and surrounding pixels
// Implement custom neighborhood processing
return pixels[y][x] // Placeholder
}
result := advancegg.ApplyNeighborhoodFunction(img, neighborhoodFilter, 1) // 1 pixel radius
package main
import (
"fmt"
"github.com/GrandpaEJ/advancegg"
)
func main() {
// Load image
img := advancegg.LoadImage("photo.jpg")
if img == nil {
fmt.Println("Failed to load image")
return
}
// Create enhancement pipeline
enhanced := enhancePhoto(img)
// Save result
advancegg.SaveJPEG(enhanced, "enhanced_photo.jpg", 95)
fmt.Println("Photo enhancement completed!")
}
func enhancePhoto(img image.Image) image.Image {
// Step 1: Noise reduction
denoised := advancegg.ApplyBilateralFilter(img, 9, 75, 75)
// Step 2: Lens correction
corrected := advancegg.ApplyBarrelDistortion(denoised, -0.05) // Slight correction
// Step 3: Exposure and contrast
exposed := advancegg.ApplyExposure(corrected, 0.2)
contrasted := advancegg.ApplyContrast(exposed, 1.15)
// Step 4: Color enhancement
vibrant := advancegg.ApplyVibrance(contrasted, 0.25)
warmed := advancegg.ApplyTemperature(vibrant, 100) // Slightly warmer
// Step 5: Sharpening
sharpened := advancegg.ApplyUnsharpMask(warmed, 1.2, 1.0, 0)
// Step 6: Final adjustments
final := advancegg.ApplyBrightnessContrast(sharpened, 1.05, 1.08)
return final
}
// Artistic filter example
func createArtisticEffect(img image.Image) image.Image {
// Create oil painting effect
oilPainting := advancegg.ApplyOilPainting(img, 4, 15)
// Add slight blur for smoothness
smoothed := advancegg.ApplyGaussianBlur(oilPainting, 1.0)
// Enhance colors
saturated := advancegg.ApplySaturation(smoothed, 1.3)
// Add warm tone
warmed := advancegg.ApplyColorTint(saturated, color.RGBA{255, 240, 220, 50})
return warmed
}