• Stars
    star
    126
  • Rank 284,543 (Top 6 %)
  • Language
    Lua
  • Created almost 12 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple Lua wrapper to graphicsmagick.

GraphicsMagick

A simple Lua wrapper to GraphicsMagick.

Only tested on Mac OSX, with GraphicsMagick installed via Homebrew.

gm.convert

This is just a binding to the command line convert utility (images are not loaded into Lua's memory). Examples:

gm = require 'graphicsmagick'
gm.convert{
   input = '/path/to/image.png',
   output = '/path/to/image.jpg',
   size = '128x128',
   quality = 95,
   verbose = true
}

gm.info

Similarly, gm.info(file) is a simple binding to the command line utility. It's handy to extra the geometry of an image, as well as its exif metadata. On top of it, if geolocation is found, the GPS location is nicely formatted.

gm = require 'graphicsmagick'
info = gm.info('some.jpeg')
print(info)
{
   width : 1024
   height : 768
   date : 2013:01:01 00:00:01
   location :
     {
       longitude : W80.13
       latitude : N25.79
     }
   format : JPEG
   exif :
     {
        Make : Apple
        FocalLength : 413/100
        ...
     }
}

gm.Image

This is a full C interface to GraphicsMagick's Wand API. We expose one Class: the Image class, which allows loading and saving images, transforming them, and importing/exporting them from/to torch Tensors.

Load library:

gm = require 'graphicsmagick'

First, we provide two high-level functions to load/save directly into/form tensors:

img = gm.load('/path/to/image.png' [, type])    -- type = 'float' (default) | 'double' | 'byte'
gm.save('/path/to/image.jpg' [,quality])        -- quality = 0 to 100 (for jpegs only)

The following provide a more controlled flow for loading/saving jpegs.

Create an image, from a file:

image = gm.Image('/path/to/image.png')
-- or
image = gm.Image()
image:load('/path/to/image.png')

Create an image, from a file, with a hint about the max size to be used:

image:load('/path/to/image.png', width [, height])

-- this tells the image loader that we won't need larger images than
-- what's specified. This can speedup loading by factors of 5 to 10.

Save an image to disk:

image:save('filename.ext')

-- where:
-- ext must be a know image format (jpg, JPEG, PNG, ...)
-- (GraphicsMagick supports tons of them)

Create an image, from a Tensor:

image = gm.Image(tensor,colorSpace,dimensions)
-- or
image = gm.Image()
image:load(tensor,colorSpace,dimensions)

-- where:
-- colorSpace is: a string made of these characters: R,G,B,A,C,Y,M,K,I
--                (for example: 'RGB', 'RGBA', 'I', or 'BGRA', ...)
--                R: red, G: green, ... I: intensity
--
-- dimensions is: a string made of these characters: D,H,W
--                (for example: 'DHW' or 'HWD')
--                D: depth, H: height, W: width

Export an image to a Tensor:

image = gm.Image('path.jpg')
image:toTensor(type,colorSpace,dimensions)

-- where:
-- type : 'float', 'double', or 'byte'
-- colorSpace : same as above
-- dimensions : same as above

When exporting Tensors, we can specify the color space:

lab = image:toTensor('float', 'LAB')
-- equivalent to:
image:colorspace('LAB')
lab = image:toTensor('float')

-- color spaces available, for now:
-- 'LAB', 'HSL', 'HWB' and 'YUV'

Images can also be read/written from/to Lua strings, or binary blobs. This is convenient for in memory manipulation (e.g. when downloading images from the web, no need to write it to disk):

blob,size = image:toBlob()
image:fromBlob(blob,size)

str = image:toString()
image:fromString(str)

In this library, we use a single function to read/write parameters (instead of the more classical get/set).

Here's an example of a resize:

-- get dimensions:
width,height = image:size()

-- resize:
image:size(512,384)

-- resize by only imposing the largest dimension:
image:size(512)

-- resize by imposing the smallest dimension:
image:size(nil,512)

Some basic transformations:

-- flip or flop an image:
image:flip()
image:flop()

Sharpen:

-- Sharpens the image whith radius=0, sigma=0.6
image:sharpen(0, 0.6)

Show an image (this makes use of Tensors, and Torch's Qt backend):

image:show()

One cool thing about this library is that all the functions can be cascaded. Here's an example:

-- Open, transform and save back:
gm.Image('input.jpg'):flip():size(128):save('thumb.jpg')

More Repositories

1

torch-ios

Torch7 for iOS.
C
196
star
2

manifold

A package to manipulate manifolds.
Lua
141
star
3

ipam-tutorials

IPAM Tutorials on Theano/Torch
Lua
129
star
4

gfx.js

A graphics backend for the browser (with a Torch7 client).
JavaScript
126
star
5

async

An async framework for Lua/Torch.
C
116
star
6

lua---nnx

An extension to Torch7's nn package.
Lua
97
star
7

lua---parallel

A (simple) parallel computing framework for Lua
Lua
92
star
8

lua---csv

A package to read and write CSV. Provides high-level database-like handlers.
Lua
47
star
9

lua---camera

A very simple camera interface (frame grabber) for Torch7.
C
34
star
10

lua---mattorch

An interface between Torch and Matlab
C
31
star
11

neuflow

Compiler toolkit for neuFlow.
Lua
26
star
12

lua---imgraph

A package to deal with graphs built on images.
C
22
star
13

lua---ffmpeg

An interface between ffmpeg and Lua/Torch
Lua
21
star
14

xLearn

A Lua-based framework for vision.
C
20
star
15

gm

GM package (for tutorial compat)
Lua
17
star
16

buffer

A buffer object for LuaJIT
Lua
15
star
17

lua---liuflow

Dense optical flow toolbox (from C.Liu)
C++
15
star
18

lua---json

A package to read/write JSON
Lua
10
star
19

thwebterm

Torch Web Terminal
JavaScript
10
star
20

videograph

This package extends imgraph, for videos...
C
9
star
21

nnop

Parameter-free Neural Network primitives for torch/nn.
Lua
9
star
22

lua---opengm

An OpenGM wrapper for Lua.
C++
8
star
23

lua---image

An image toolBox for Torch7.
Lua
7
star
24

persist

Persist: a simple persisting table for Torch (uses Redis as a data store).
Lua
5
star
25

torchinstall

A one-line install script for Torch
Shell
5
star
26

restclient

A simple Lua client for REST APIs.
Lua
5
star
27

lua---nng

A graph extension to Torch7's nn package.
Lua
4
star
28

thmap

Trivial distributed computing for Torch.
Lua
4
star
29

lua---inline-C

An Inline C package for Lua
Lua
4
star
30

operator-library

A library of fast customizable operators, in Verilog.
3
star
31

xrocks

A simple container for all our Lua rocks.
Shell
3
star
32

lua-fs-0.3

lua FS library, with torch-pkg build
C
3
star
33

lua---bitop

LuaBitOp -- from Mike Pall (repackaged for Torch7)
Lua
3
star
34

luasql

LuaSQL, fork from https://github.com/keplerproject/luasql, adapted to Torch.
C
3
star
35

lua---python

Python in Lua.
C
3
star
36

lua---sys

A sys/unix utility package for Lua
Lua
2
star
37

nnfunc

Functional API for nn.
Lua
2
star
38

lbfgs

LibLBFGS (C Lib) wrapper.
Lua
2
star
39

luaforever

LuaForever: run a script forever.
JavaScript
2
star
40

selflua

self contained lib for lua
C
1
star
41

THC

This is the raw C api from Torch7.
C
1
star
42

lua---xml

XML Interface.
C
1
star
43

rawptr

just a raw ptr (2-way) interface to share Storages in Lua
C
1
star
44

lua---debugger

Debugger for Lua
Lua
1
star
45

lua---xlua

A few functions to make life better from the Lua prompt (lua -lxlua).
Lua
1
star
46

lua---lushmat

A simple package to load lush matrices as torch Tensors.
C
1
star
47

nn2

A next version of nn.
Lua
1
star