Convert Figma logo to code with AI

anthonynsimon logobild

Image processing algorithms in pure Go

4,032
215
4,032
20

Top Related Projects

5,320

Imaging is a simple image processing package for Go

4,468

Go Graphics - 2D rendering in Go with a simple API.

10,369

Content aware image resize library

2,750

Go package for fast high-level image processing powered by libvips C library

3,024

Pure golang image resizing

Quick Overview

The bild project is a Go library for image processing and manipulation. It provides a wide range of image processing functions, including basic operations like resizing, cropping, and rotating, as well as more advanced features like color adjustments, filters, and image composition.

Pros

  • Extensive Functionality: bild offers a comprehensive set of image processing capabilities, making it a versatile tool for a wide range of image-related tasks.
  • Performance: The library is written in Go, which is known for its efficiency and speed, allowing for fast image processing operations.
  • Flexibility: The library's modular design and well-documented API make it easy to integrate into various projects and customize as needed.
  • Active Development: The project is actively maintained, with regular updates and improvements to the codebase.

Cons

  • Limited Documentation: While the project has a good amount of documentation, some areas could be more detailed and user-friendly, especially for beginners.
  • Steep Learning Curve: Mastering the full capabilities of bild may require a significant investment of time and effort, especially for developers who are new to image processing.
  • Lack of GUI: The library is primarily focused on programmatic image processing, and does not provide a graphical user interface (GUI) for end-users.
  • Dependency on Go: As a Go-based library, bild may not be as accessible to developers who are more familiar with other programming languages.

Code Examples

Here are a few examples of how to use the bild library:

  1. Resizing an Image:
import "github.com/anthonynsimon/bild/transform"

img, err := bild.Open("input.jpg")
if err != nil {
    // handle error
}

resizedImg := transform.Resize(img, 200, 200, transform.Linear)
err = bild.Save("output.jpg", resizedImg)
if err != nil {
    // handle error
}
  1. Applying a Grayscale Filter:
import "github.com/anthonynsimon/bild/filter"

img, err := bild.Open("input.jpg")
if err != nil {
    // handle error
}

grayscaleImg := filter.Grayscale(img)
err = bild.Save("output.jpg", grayscaleImg)
if err != nil {
    // handle error
}
  1. Compositing Two Images:
import "github.com/anthonynsimon/bild/blend"

img1, err := bild.Open("image1.jpg")
if err != nil {
    // handle error
}

img2, err := bild.Open("image2.jpg")
if err != nil {
    // handle error
}

compositeImg := blend.Over(img1, img2)
err = bild.Save("output.jpg", compositeImg)
if err != nil {
    // handle error
}
  1. Applying a Gaussian Blur:
import "github.com/anthonynsimon/bild/filter"

img, err := bild.Open("input.jpg")
if err != nil {
    // handle error
}

blurredImg := filter.Gaussian(img, 5.0)
err = bild.Save("output.jpg", blurredImg)
if err != nil {
    // handle error
}

Getting Started

To get started with the bild library, follow these steps:

  1. Install the library using Go's package manager:
go get github.com/anthonynsimon/bild
  1. Import the library in your Go project:
import "github.com/anthonynsimon/bild"
  1. Explore the library's documentation and API to find the functions and features you need for your image processing tasks. The README and GoDoc provide a good starting point.

  2. Start writing your image processing code using the bild

Competitor Comparisons

5,320

Imaging is a simple image processing package for Go

Pros of imaging

  • More comprehensive feature set, including advanced image processing operations
  • Better documentation and examples
  • Actively maintained with regular updates

Cons of imaging

  • Slightly more complex API, potentially steeper learning curve
  • Larger codebase, which may impact compilation times and binary size

Code Comparison

bild:

img, err := bild.Open("input.jpg")
result := bild.Blur(img, 3.0)
err = bild.Save("output.jpg", result, bild.JPEGEncoder(95))

imaging:

src, err := imaging.Open("input.jpg")
dst := imaging.Blur(src, 3.0)
err = imaging.Save(dst, "output.jpg")

Both libraries offer similar functionality for basic image processing tasks. imaging provides a more extensive set of features, while bild focuses on simplicity and ease of use. The choice between them depends on the specific requirements of your project and the level of image processing complexity you need.

4,468

Go Graphics - 2D rendering in Go with a simple API.

Pros of GG

  • GG is a lightweight and fast 2D rendering library, making it suitable for games and other performance-critical applications.
  • GG provides a simple and intuitive API, making it easy to use and integrate into existing projects.
  • GG has a wide range of built-in shapes, transformations, and effects, allowing for the creation of complex graphics.

Cons of GG

  • GG is a relatively small and focused library, which may not provide the same level of functionality as a more comprehensive image processing library like Bild.
  • GG is primarily focused on 2D rendering, and may not be as well-suited for more advanced image processing tasks.
  • The documentation for GG may not be as extensive as that of Bild, which could make it more challenging for new users to get started.

Code Comparison

Bild:

img := bild.New(100, 100)
img.Fill(color.RGBA{255, 0, 0, 255})
img.DrawCircle(50, 50, 25, color.RGBA{0, 255, 0, 255})

GG:

gg := gg.NewContext(100, 100)
gg.SetColor(color.RGBA{255, 0, 0, 255})
gg.Fill()
gg.SetColor(color.RGBA{0, 255, 0, 255})
gg.DrawCircle(50, 50, 25)
gg.Fill()
10,369

Content aware image resize library

Pros of caire

  • Focuses specifically on content-aware image resizing (seam carving)
  • Offers face detection to preserve important features during resizing
  • Provides both CLI and library interfaces for flexibility

Cons of caire

  • More limited in scope compared to bild's broader image processing capabilities
  • May have a steeper learning curve for users unfamiliar with seam carving concepts
  • Potentially slower performance for large images due to complex algorithms

Code Comparison

caire (Go):

s := caire.NewCarver(width, height)
s.NewProc(input).Scale(newWidth, newHeight)
s.Process(output)

bild (Go):

result := bild.Resize(img, width, height, bild.Linear)
f, _ := os.Create(output)
png.Encode(f, result)

Summary

caire specializes in content-aware image resizing, offering advanced features like face detection. It provides both CLI and library interfaces but has a narrower focus compared to bild. bild, on the other hand, offers a wider range of image processing functions with a simpler API, making it more suitable for general-purpose image manipulation tasks. The choice between the two depends on whether you need specialized content-aware resizing (caire) or a more comprehensive image processing toolkit (bild).

2,750

Go package for fast high-level image processing powered by libvips C library

Pros of bimg

  • Supports a wider range of image formats, including JPEG, PNG, GIF, TIFF, and WebP.
  • Provides a more extensive set of image processing operations, such as resizing, cropping, and color adjustments.
  • Offers a more concise and intuitive API for performing image manipulations.

Cons of bimg

  • Has a smaller community and fewer contributors compared to Bild.
  • May have less comprehensive documentation and support resources available.
  • Potentially slower performance for certain image processing tasks.

Code Comparison

Bild:

img, err := bild.Open("image.jpg")
if err != nil {
    // handle error
}

img = bild.Resize(img, 200, 200, bild.LanczosResampling)
err = bild.Save("resized.jpg", img)
if err != nil {
    // handle error
}

bimg:

img, err := bimg.Read("image.jpg")
if err != nil {
    // handle error
}

img, err = img.Resize(200, 200)
if err != nil {
    // handle error
}

err = img.Write("resized.jpg")
if err != nil {
    // handle error
}
3,024

Pure golang image resizing

Pros of resize

  • More focused and specialized for image resizing operations
  • Generally faster performance for resizing tasks
  • Simpler API with fewer dependencies

Cons of resize

  • Limited to resizing operations, lacking broader image processing capabilities
  • Less actively maintained, with fewer recent updates
  • Smaller community and ecosystem compared to bild

Code Comparison

resize:

m := resize.Resize(300, 0, img, resize.Lanczos3)

bild:

resized := transform.Resize(img, 300, 0, transform.Linear)

Both libraries offer simple one-line resizing operations, but bild provides more options for image processing beyond just resizing. resize focuses solely on efficient resizing algorithms, while bild offers a wider range of image manipulation functions.

resize is a good choice for projects that primarily need fast and efficient image resizing, while bild is better suited for applications requiring a broader set of image processing capabilities. The choice between the two depends on the specific needs of your project and the balance between specialization and versatility.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

bild

bild logo

MIT License GoDoc Go Report Card

A collection of parallel image processing algorithms in pure Go.

The aim of this project is simplicity in use and development over absolute high performance, but most algorithms are designed to be efficient and make use of parallelism when available.

It uses packages from the standard library whenever possible to reduce dependency use and development abstractions.

All operations return image types from the standard library.

Documentation

The documentation for the various packages is available here.

CLI usage

Download and compile from sources:

go get github.com/anthonynsimon/bild

Or get the pre-compiled binaries for your platform on the releases page

bild

A collection of parallel image processing algorithms in pure Go

Usage:
  bild [command]

Available Commands:
  adjust      adjust basic image features like brightness or contrast
  blend       blend two images together
  blur        blur an image using the specified method
  channel     channel operations on images
  effect      apply effects on images
  help        Help about any command
  histogram   histogram operations on images
  imgio       i/o operations on images
  noise       noise generators
  segment     segment an image using the specified method

Flags:
  -h, --help      help for bild
      --version   version for bild

Use "bild [command] --help" for more information about a command.

For example, to apply a median effect with a radius of 1.5 on the image input.png, writing the result into a new file called output.png:

bild effect median --radius 1.5 input.png output.png

Install package

bild requires Go version 1.11 or greater.

go get github.com/anthonynsimon/bild/...

Basic package usage example:

package main

import (
    "github.com/anthonynsimon/bild/effect"
    "github.com/anthonynsimon/bild/imgio"
    "github.com/anthonynsimon/bild/transform"
)

func main() {
    img, err := imgio.Open("input.jpg")
    if err != nil {
        fmt.Println(err)
        return
    }

    inverted := effect.Invert(img)
    resized := transform.Resize(inverted, 800, 800, transform.Linear)
    rotated := transform.Rotate(resized, 45, nil)

    if err := imgio.Save("output.png", rotated, imgio.PNGEncoder()); err != nil {
        fmt.Println(err)
        return
    }
}

Output examples

Adjustment

import "github.com/anthonynsimon/bild/adjust"

Brightness

result := adjust.Brightness(img, 0.25)

example

Contrast

result := adjust.Contrast(img, -0.5)

example

Gamma

result := adjust.Gamma(img, 2.2)

example

Hue

result := adjust.Hue(img, -42)

example

Saturation

result := adjust.Saturation(img, 0.5)

example

Blend modes

import "github.com/anthonynsimon/bild/blend"

result := blend.Multiply(bg, fg)
AddColor BurnColor Dodge
DarkenDifferenceDivide
ExclusionLightenLinear Burn
Linear LightMultiplyNormal
OpacityOverlayScreen
Soft LightSubtract

Blur

import "github.com/anthonynsimon/bild/blur"

Box Blur

result := blur.Box(img, 3.0)

example

Gaussian Blur

result := blur.Gaussian(img, 3.0)

example

Channel

import "github.com/anthonynsimon/bild/channel"

Extract Channels

result := channel.Extract(img, channel.Alpha)

example

Extract Multiple Channels

result := channel.ExtractMultiple(img, channel.Red, channel.Alpha)

Effect

import "github.com/anthonynsimon/bild/effect"

Dilate

result := effect.Dilate(img, 3)

example

Edge Detection

result := effect.EdgeDetection(img, 1.0)

example

Emboss

result := effect.Emboss(img)

example

Erode

result := effect.Erode(img, 3)

example

Grayscale

result := effect.Grayscale(img)

example

Invert

result := effect.Invert(img)

example

Median

result := effect.Median(img, 10.0)

example

Sepia

result := effect.Sepia(img)

example

Sharpen

result := effect.Sharpen(img)

example

Sobel

result := effect.Sobel(img)

example

Unsharp Mask

result := effect.UnsharpMask(img, 0.6, 1.2)

example

Histogram

import "github.com/anthonynsimon/bild/histogram"

RGBA Histogram

hist := histogram.NewRGBAHistogram(img)
result := hist.Image()

example

Noise

import "github.com/anthonynsimon/bild/noise"

Uniform colored

result := noise.Generate(280, 280, &noise.Options{Monochrome: false, NoiseFn: noise.Uniform})

example

Binary monochrome

result := noise.Generate(280, 280, &noise.Options{Monochrome: true, NoiseFn: noise.Binary})

example

Gaussian monochrome

result := noise.Generate(280, 280, &noise.Options{Monochrome: true, NoiseFn: noise.Gaussian})

example

Perlin Noise

result := noise.GeneratePerlin(280, 280, 0.25)

example

Paint

import "github.com/anthonynsimon/bild/paint"

Flood Fill

// Fuzz is the percentage of maximum color distance that is tolerated
result := paint.FloodFill(img, image.Point{240, 0}, color.RGBA{255, 0, 0, 255}, 15)

example

Segmentation

import "github.com/anthonynsimon/bild/segment"

Threshold

result := segment.Threshold(img, 128)

example

Transform

import "github.com/anthonynsimon/bild/transform"

Crop

// Source image is 280x280
result := transform.Crop(img, image.Rect(70,70,210,210))

example

FlipH

result := transform.FlipH(img)

example

FlipV

result := transform.FlipV(img)

example

Resize Resampling Filters

result := transform.Resize(img, 280, 280, transform.Linear)
Nearest NeighborLinearGaussian
Mitchell NetravaliCatmull RomLanczos

Rotate

// Options set to nil will use defaults (ResizeBounds set to false, Pivot at center)
result := transform.Rotate(img, -45.0, nil)

example

// If ResizeBounds is set to true, the full rotation bounding area is used
result := transform.Rotate(img, -45.0, &transform.RotationOptions{ResizeBounds: true})

example

// Pivot coordinates are set from the top-left corner
// Notice ResizeBounds being set to default (false)
result := transform.Rotate(img, -45.0, &transform.RotationOptions{Pivot: &image.Point{0, 0}})

example

Shear Horizontal

result := transform.ShearH(img, 30)

example

Shear Vertical

result := transform.ShearV(img, 30)

example

Translate

result := transform.Translate(img, 80, 0)

example

Contribute

Want to hack on the project? Any kind of contribution is welcome!
Simply follow the next steps:

  • Fork the project.
  • Create a new branch.
  • Make your changes and write tests when practical.
  • Commit your changes to the new branch.
  • Send a pull request, it will be reviewed shortly.

In case you want to add a feature, please create a new issue and briefly explain what the feature would consist of. For bugs or requests, before creating an issue please check if one has already been created for it.

Changelog

Please see the changelog for more details.

License

This project is licensed under the MIT license. Please read the LICENSE file.