NekoLib: an easy-to-use image manipulation library

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Ubermann
Party member
Posts: 146
Joined: Mon Nov 05, 2012 4:00 pm

NekoLib: an easy-to-use image manipulation library

Post by Ubermann »

NekoLib: an user-friendly image manipulation library



Last version: 1.0 from 24-Jan-2013
DOWNLOAD (attachment .lua): download/file.php?mode=view&id=6761 <= DLoad deactivated until next version with new lib name!!!!

NekoLib is a (right now) simple library written in pure LÖVE for image manipulation.

It is system independent, and easy to use.

You may use it within your programs without having to adapt it to the library.

You only need to do require "neko" to have access to all lib functionalities.

1.- What NekoLib does exactly?

What NekoLib do is to process any image and return the processed result.

Because NekoLib was done having into account multiple and consecutive filters applies, you may pass to the filters a path to an image or a variable with ImageData data.

This way, you can process multiple times any ImageData without having to save and load the image.

Some sample images:

Original image:
http://holaandroid.com/wp-content/uploa ... rvalds.jpg

Sepia image for all image size:
nvl807j.png
nvl807j.png (249.67 KiB) Viewed 982 times
Image with green colors removed
JA9eSvH.png
JA9eSvH.png (233.56 KiB) Viewed 982 times
Face green colors values replaced with blues values and contrast increased:
nCa8OTN.png
nCa8OTN.png (273.52 KiB) Viewed 982 times
Face noisificated with RGB noise and then colors inverted:
zpOUXXE.png
zpOUXXE.png (305.07 KiB) Viewed 982 times

2.- How can I apply a filter to an image with NekoLib?

It's so simple that even a 2-yo kid would be able to do that!!!

- The first thing to do is to download NekoLib (see attachment below) and save the file to your project folder.

- Next, in your main.lua file add a line in the top like require "neko".

- Finally, you can summon any filter from anywhere in your code. All filters will require you to specify the image to be modified, the X and Y position of the image to start the filtering and the width and height of the part of the image to be filtered.
For example, I have an image that is 600x600, but I can tell NekoLib to only modify an area of 200x200 where the top-left corner in in x=75, y=400

With a real example:

myImage = neko.grayscale("someImage.png", 100, 100, 400, 250) <<== This will convert to grayscale a zone in the image from (100,100) to (500,350)

myImage = neko.sepia("someImage.png", 0, 0, 600, 600) <<== If the original image was 600x600, then this will convert to sepia color all image.


But some other more complex filters will require more arguments, so you should read the API reference to know all this info.

Also, we said that NekoLib was created to allow batch image processing, so you can apply multiple and consecutive filters to the same image without having to save it to hard dist and load again.

When you apply a filter to an image, NekoLib will return always an ImageData value, which is the modified image, so you can do:

myImage = neko.invert("someImage.png", 0, 0, 600, 600)
myImage = neko.sepia(myImage, 0, 0, 600, 600)


So you will have into myImage a color-inverted and sepia-recolored image, instead of the original one.

One important thing to remember is: images start at (0, 0) and end at image_width - 1 and imageHeight - 1!!!!!

3.- List of filters and brief description:

This is the place you should come to review all filters provided by NekoLib.

neko.sepia( <imagePath>, <x>, <y>, <w>, <h> )
Converts the image to sepia colors

neko.invert( <imagePath>, <x>, <y>, <w>, <h> )
Inverts the colors in the image

neko.grayscale( <imagePath>, <x>, <y>, <w>, <h>, [<mode>: "max"|"min"] )
Turns the image to gray scale colors, using mid colors (default), max values or min values.

neko.remove( <imagePath>, <x>, <y>, <w>, <h>, <color>: "r"|"g"|"b" )
Removes <color> from the image in the RGB values, making it zero.

neko.bright( <imagePath>, <x>, <y>, <w>, <h>, [<amount>] )
Set the <brightness> level to the image to the specified <amount>

neko.alpha( <imagePath>, <x>, <y>, <w>, <h>, [<amount>:(0..255)] )
Sets the <alpha> value to the image to the specified <amount>

neko.contrast( <imagePath>, <x>, <y>, <w>, <h>, [<amount>:(-255..255)] )
Changes image <contrast> to the specified <amount>

neko.sink( <imagePath>, <x>, <y>, <w>, <h>, [<amount>:(0..255)], [<threshold>:(0..255)] )
Reduces by the specified <amount> the colors that are at or below the specified <threshold>

neko.replace( <imagePath>, <x>, <y>, <w>, <h>, <target>:"r"|"g"|"b", <color>:"r"|"g"|"b" )
Replaces <target> color value in the RGB value with <color> color value in the RGB color value.
Ex: neko.replace("image.png", 0, 0, 100, 100, "r", "g") <= replaces red value with the value in green

neko.noise( <imagePath>, <x>, <y>, <w>, <h>, [<threshold>:(0, 100)], [<noRGB>:true|false] )
Generates random RGB noise with a chance of <threshold>. Setting <noRGB> to true will generate gray scale noise instead.

neko.colorToAlpha( <imagePath>, <x>, <y>, <w>, <h>, [<color>:"r"|"g"|"b"], [<alpha>:(0..255)] )
Sets the <alpha> value to the specified, for the <color>, when this <color> value is higher that any other in the RGB color value.
Last edited by Ubermann on Fri Jan 25, 2013 9:38 am, edited 1 time in total.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: IroLib: an easy image manipulation library

Post by Ref »

Nice library.
Good work!
Really dumb suggestion, how about doing the same thing using PixelEffects?
If I'm not mistaken (as usual) should be substantially faster?
User avatar
Ubermann
Party member
Posts: 146
Joined: Mon Nov 05, 2012 4:00 pm

Re: IroLib: an easy image manipulation library

Post by Ubermann »

Ref wrote:Nice library.
Good work!
Really dumb suggestion, how about doing the same thing using PixelEffects?
If I'm not mistaken (as usual) should be substantially faster?
Becuase I don't know GLSL syntax and as far as i know some shader functions may not be compatible in every system.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: IroLib: an easy image manipulation library

Post by vrld »

It would be cool if you add functions to transform the color space (at least RGB <-> HSL) and to convolve an image with a custom filter-kernel and maybe functions to create common kernels (e.g. blur, sharpen, sobel, ...). Some histogram operations (equalization, thresholding, ...) would also be nice to have.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: IroLib: an easy image manipulation library

Post by Ref »

I presume you know that there is already a commercial library called IROLIB.
Don’t know who has precedence.
There is a concern that the IROLIB.DLL contans a trojan so it may not be too go a choice for a new library name.
User avatar
Ubermann
Party member
Posts: 146
Joined: Mon Nov 05, 2012 4:00 pm

Re: IroLib: an easy image manipulation library

Post by Ubermann »

vrld wrote:It would be cool if you add functions to transform the color space (at least RGB <-> HSL) and to convolve an image with a custom filter-kernel and maybe functions to create common kernels (e.g. blur, sharpen, sobel, ...). Some histogram operations (equalization, thresholding, ...) would also be nice to have.
Yes, I will be adding more "filters" and functionalities.
The actual filters are the simple ones. Of course I will add kerneled filters and the RGB <-> HSV idea sounds great, although I don't know if it will be any useful.

Also I will work more on error handling and incorrect data parameters passed, making the app not to crash.
Ref wrote:I presume you know that there is already a commercial library called IROLIB.
Don’t know who has precedence.
There is a concern that the IROLIB.DLL contans a trojan so it may not be too go a choice for a new library name.
I didn't know.
That makes me sad because Iro means color in Japanese, and I really wanted to use that word.

I will have to think another name...
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests