Repository navigation
Filters
Filters work-flow is similar to core functionalities usage.
First you need to create ImageProcessing object and open an image file.
ImageProcessing image = new ImageProcessing();
image.open("/home/user/city.jpg");Next step is to create filter object and apply it to processed image.
GrayscaleFilter filter = new GrayscaleFilter();
image.applyFilter(filter);
// OR
image.applyFilter(filter, 0, 0, 400, 500);First method applies filter to whole image. Second, overloaded method can be used to define area, on which filter will be applied.
Final step is to save processed image to file.
image.save("/home/user/output.jpg");Grayscale filter allows to desaturate an image.
Default constructor creates filter, that uses each color channel with the same strength, when desaturating an image.
GrayscaleFilter filter = new GrayscaleFilter();
image.applyFilter(filter);Custom construtor allows to define strength of each channel, when converting image to gray scale.
GrayscaleFilter redFilter = new GrayscaleFilter(1f, 0f, 0f);
GrayscaleFilter greenFilter = new GrayscaleFilter(0f, 1f, 0f);
GrayscaleFilter blueFilter = new GrayscaleFilter(0f, 0f, 1f);
image.applyFilter(redFilter, 0, 0, 260, 500);
image.applyFilter(greenFilter, 260, 0, 280, 500);
image.applyFilter(blueFilter, 540, 0, 260, 500);Sum of all channels should be equal or at least close to 1 to keep image brightness at the same level. If sum will be higher, processed image will be lighter. If sum will be lower, processed image will be darker.
Matrix filter allows to use one of many different convolution matrices with various effects.
Simple example of this functionality would be blurring an image:
float[][] matrix = {
{0.111f, 0.111f, 0.111f},
{0.111f, 0.111f, 0.111f},
{0.111f, 0.111f, 0.111f}
};
MatrixFilter filter = new MatrixFilter(matrix);
image.applyFilter(filter);To blur image with gaussian algorithm just create filter with specified size and apply it to image.
GaussianBlurFilter filter = new GaussianBlurFilter(8);
image.applyFilter(filter);Below result of applying stronger blur with size 32.
InvertColorsFilter is simple, not customizable filter to invert colors of an image.
InvertColorsFilter filter = new InvertColorsFilter();
image.applyFilter(filter);Mosaic filter creates large pixels with color calculated as average value of all merged pixels.
MosaicFilter filter = new MosaicFilter(24);
image.applyFilter(filter);WatermarkFilter allows to place watermarks on image. There are two versions of this filter and because of highly customizable configuration builder is provided to create instances of this filter.
First watermark file is needed.
Now we can load it and use as watermark on image.
To place single watermark in desired location SINGLE filter version should be used
ImageDrawEntity watermark = image.load("/home/user/github.png");
WatermarkFilter filter = new WatermarkFilter.Builder()
.setType(WatermarkFilterType.SINGLE)
.setWatermark(watermark)
.setLocation(WatermarkLocation.LOWER_LEFT)
.setMargin(10)
.build();
image.applyFilter(filter);WatermarkLocation allows to choose, where to place watermark (it can be one of four corners or center of image) and margin allows to define how far from edges of image it should be rendered.
To place watermarks on whole image area REPEATED version should be used. With minimal configuration it will fill tight whole image with watermarks.
ImageDrawEntity watermark = image.load("/home/user/github.png");
WatermarkFilter filter = new WatermarkFilter.Builder()
.setType(WatermarkFilterType.REPEATED)
.setWatermark(watermark)
.build();
image.applyFilter(filter);Spacing between watermarks can be changed with setHorizontalSpacing() and setVerticalSpacing() builder methods.
ImageDrawEntity watermark = image.load("/home/user/github.png");
WatermarkFilter filter = new WatermarkFilter.Builder()
.setType(WatermarkFilterType.REPEATED)
.setWatermark(watermark)
.setHorizontalSpacing(60)
.setVerticalSpacing(60)
.build();
image.applyFilter(filter);It is possible also to move watermarks from edge of image by changing initial offset with methods setXOffset() and setYOffset()
ImageDrawEntity watermark = image.load("/home/user/github.png");
WatermarkFilter filter = new WatermarkFilter.Builder()
.setType(WatermarkFilterType.REPEATED)
.setWatermark(watermark)
.setHorizontalSpacing(60)
.setVerticalSpacing(60)
.setXOffset(50)
.setYOffset(10)
.build();
image.applyFilter(filter);










