carve

package module
Version: v0.0.0-...-5e7ef0c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2017 License: MIT Imports: 5 Imported by: 2

README

carve

Go implementation of Seam Carving algorithm. Seam carving allows for an image to be resized without simply cropping or scaling the original image. Detailed walk through of the algorithm and code can be found on my website. Algorithm is also detailed on Wikipedia, the original paper.

Installation

$ go get https://github.com/aaparella/carve

Usage

resized, err := carve.ReduceHeight(img, 50)
if err != nil {
    log.Fatal(err)
}

Todo

  • Improve performance
    • Reduce heap allocations
    • Caching?

Documentation

Overview

Package carve implements the seam carving algorithm for dyanmic image resizing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateCostMatrix

func GenerateCostMatrix(im image.Image) [][]float64

GenerateCostMatrix creates a matrix indicating the cumulative energy of the lowest cost seam from the left of the image to each pixel.

mat[x][y] is the cumulative energy of the seam that runs from the left of the image to the pixel at column x, row y.

func GenerateEnergyMap

func GenerateEnergyMap(im image.Image) image.Image

GenerateEnergyMap applies grayscale and sobel filters to the input image to create an energy map.

func ReduceHeight

func ReduceHeight(im image.Image, n int) (image.Image, error)

ReduceHeight uses seam carving to reduce height of given image by n pixels.

func ReduceWidth

func ReduceWidth(im image.Image, n int) (image.Image, error)

ReduceWidth uses seam carving to reduce width of given image by n pixels.

func RemoveSeam

func RemoveSeam(im image.Image, seam Seam) image.Image

RemoveSeam creates a copy of the provided image, with the pixels at the points in the provided seam removed.

Types

type Point

type Point struct {
	X, Y int
}

Point defines an X Y point in an image.

type Seam

type Seam []Point

Seam defines a sequence of pixels through an image to be removed.

func FindLowestCostSeam

func FindLowestCostSeam(mat [][]float64) Seam

FindLowestCostSeam uses a cumulative cost matrix to identify the seam with the lowest total cumulative energy.

func GenerateSeam

func GenerateSeam(im image.Image) Seam

GenerateSeam returns the optimal horizontal seam for removal.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL