Skip to content

A content aware image seam-carving package for Go written in a few lines of code

Notifications You must be signed in to change notification settings

OSokunbi/image-carve

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

using the carver package

using the carver package in your own projects is pretty simple, you need to import it like so

import "github.com/OSokunbi/image-carve/carver"

then run

go get -u github.com/OSokunbi/image-carve/carver

there is a total of 4 functions that you can use from the carver package

  1. carver.Carve - this function takes in am image as well as a target height and width for that image and returns a new image that is the target height and width

  2. carver.Rotate90 - this function takes in an image and returns a new image that is rotated 90 degrees

  3. carver.RotateMinus90 - this function takes in an image and returns a new image that is rotated -90 degrees

  4. caver.Energy - this function takes in an image and calculates the energy of each pixel in the image, returning this as a 2D slice of floats

Examples of how to use these functions can be found in the main.go file in the root of this repository

running main.go

to run the main.go file in the root of this repository, you can use the following command:

go build main.go

this will create an executable file called main in the root of the repository, you can then run this file using the following command:

./main -filename=<path to image> -height=<target height> -width=<target width>

where:

- `<path to image>` is the path to the image you want to carve
- `<target height>` is the target height of the new image
- `<target width>` is the target width of the new image

a new jpg image will be saved in the root of the repository with the name output.jpg

here's an example, take an original image

original image

it originally has the following dimensions

width: 800px
height: 400px

say you wanted to resize this image for a profile picture, but its originally too large to make it your profile picture without losing a lot of import details in the image, you could resize it like so

./main -filename=./images/example.jpg -height=400 -width=400

the image now has the following dimensions

width: 400px
height: 400px

and looks like this

carved image

peace :P

ʕ˙Ⱉ˙ʔ rawr!

About

A content aware image seam-carving package for Go written in a few lines of code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages