[PLUGIN]image processing

Enter this post to DOWNLOAD latest release: proc 1.0

Name: imageprocessing

Author: Bhou

Version: 1.0

Platform: Windows (binary not available now), Linux, MacOS(binary not available now)

Program Language: C, Lua

Website: not available

Description: an image process lib

Download: imageprocessing_linux_1.0.zip

Dependency: libffw3-3


Image processing  is C-implemented library for image processing. It is wrapped into PLxPLs Lua OOP Class. This plugin provides several image process functions.

Supported image format: BMP


Load an image from file

-- import CImage class
local CImage = require( "plxpls.imageprocessing.oo.data.CImage" );
-- load the image, image type now only support 'BMP'
img = oo.new( CImage, <string:image path>, [string:image type] );

Create an empty image

img = oo.new( CImage, <number:width>, <number:height>, <number:bitdepth>, <number:alpha> );

Save an image

img:save( <string:path>, <string:image type> );

Get raw image, raw image is the internal memory block


Create an image according to the raw image

img = oo.new( CImage, <usrdata:raw image> );

Clone/Copy an image

cpyImg1 = img:clone();
cpyImg2 = img:copy();

Get a window image

window = img:getWindow( left, top, width, height );

Get binary image

-- a binary image is an image with pixel 0 or 1
binary = img:getBinaryImage( threshold );

Call Centroid algorithm

-- call centroid algorithm in x direction
centerX = img:centroidX();

Transfer a color image to grayscale image

-- usually, the r,g,b ratio used to transfer is 0.3:0.59:0.11
grayImage = img:transferToGrayscale( red_ratio, green_ratio, blue_ratio );

Fourier transform

-- return the real part and imaginary part 
re, im = img:fourierTransform();

Inverse Fourier transform

-- a static function, return the image from the real part and imaginary part
local invImage = CImage.inverseFourierTransform( re, im );

Low pass filter

-- a static function, modify the re and im part with a low pass filter
local a, b = CImage.lowpass( re, im, threshold );

Get Spectrum image according to the fourier transform

-- this is a static function 
moduleImg, phaseImg = CImage.getSpectrImage( real, imaginary, factor, percent );

Sum up all the pixels of a gray-scale image / get the power of the image

-- this function is implemented in pure lua, might have a performance issue, can be rewritten in C
power = img:getPower();

Arthmetic operation

-- add a constant number for all pixels
img:addConst( constant );
-- add another image
img:add( img2 );
-- subtract a constant number for all pixels
img:subtractConst( constant );
-- subtract another image
img:subtract( img2 );
-- divide a constant number for all pixels
img:divideConst( constant );
-- divide another image
img:divide( img2 );

Image attribute access

-- get pixel r, g, b value
r,g,b = img:getPixel( x, y );
-- get image width
width = img:getWidth();
-- get image height
height = img:getHeight();
-- set image pixel
img:setPixel( x, y, r, g, b, a );

What’s New


One thought on “[PLUGIN]image processing

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s