Node.js module for pixel sorting.
This Node.js module is based on the RubyGem pxlsrt. Pixel sorting is where an image is divided into sections (called "bands" in pxlsrt nomenclature) and those sections are in turn sorted based off of properties of the pixels within them. Pxlsrt is a basic library that allows you to do this.
npm install pxlsrt
Check out example/example.js for examples.
import Pxlsrt from 'pxlsrt';
Pxlsrt.read('./test.png').then(image => {
image.filter('brute', { min: 10, max: 20, method: 'saturation', direction: 'vertical' }).write('./output.png');
})
There is a browser-friendly version as well. The only differences are that it loads a browser-friendly version of Jimp and removes methods that can't be taken in the browser (like writing to a file). Please note that even when minimized, this will be a pretty large file because of Jimp and its dependencies.
import Pxlsrt from 'pxlsrt/dist/browser';
Pxlsrt implements filters which affect how the image is pixel sorted. There are two filters included by default, "Brute" and "Smart". Pxlsrt is also extensible so custom filters can be written and included.
Filters are not required to have these options, but the default filters have these in common:
{1 2 3 4 5 6}
middlated once is {5 3 1 2 4 6}
. You can loop and apply middlation multiple times or applying the process in reverse.
The Brute filter doesn't care about the contents of the image. Brute randomly divides the image into bands within a range of length. It is then sorted within those bands.
The Smart filter uses edge detection to find regions of the image which it then sorts.
Pxlsrt filters are based off of the Filter
class and added via the FilterCollection
. The filters that are included by default are built on top of DefaultFilter
in order to centralize some of the common processes. Below is an example of how to create your own filter and apply it.
import Pxlsrt from 'pxlsrt';
class MyFilter extends Pxlsrt.Filter { // Alternatively, extend Pxlsrt.DefaultFilter
// Your filter must override the run function
// It only accepts two arguments:
// - image: Pxlsrt.Image that is calling the filter.
// - options: Object with options for the filter.
static run(image, options = {}) {
// Apply some effects to image
return image;
}
}
module.exports = MyFilter;
import Pxlsrt from 'pxlsrt';
import MyFilter from './myfilter.js';
Pxlsrt.FilterCollection.add('myfilter', MyFilter);
Pxlsrt.read('./test.png').then(image => {
image.filter('myfilter').write('./output.png');
});
To see classes and functions, run jsdoc and checkout the docs folder:
npm run jsdoc
Pxlsrt is licensed under the MIT license.