Java Utililty Methods BufferedImage Operation

List of utility methods to do BufferedImage Operation

Description

The list of methods to do BufferedImage Operation are organized into topic(s).

Method

voidbinarize(BufferedImage image)
binarize
for (int i = 0; i < image.getWidth(); i++)
    for (int j = 0; j < image.getHeight(); j++)
        image.setRGB(i, j, gamma(image.getRGB(i, j)) > 127 ? Color.white.getRGB() : Color.black.getRGB());
BufferedImagebinarize(BufferedImage original)
binarize
int red;
int newPixel;
int threshold = otsuTreshold(original);
BufferedImage binarized = new BufferedImage(original.getWidth(), original.getHeight(), original.getType());
for (int i = 0; i < original.getWidth(); i++) {
    for (int j = 0; j < original.getHeight(); j++) {
        red = new Color(original.getRGB(i, j)).getRed();
        int alpha = new Color(original.getRGB(i, j)).getAlpha();
...
BufferedImagebinary(BufferedImage src)
binary
int width = src.getWidth();
int height = src.getHeight();
BufferedImage grayImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
for (int i = 0; i < width; i++) {
    for (int j = 0; j < height; j++) {
        int rgb = src.getRGB(i, j);
        grayImage.setRGB(i, j, rgb);
return grayImage;
BufferedImageblackAndWhiteCleaning(BufferedImage image)
This method cleans input image by replacing all non black pixels with white pixels
for (int j = 0; j < image.getHeight(); j++) {
    for (int i = 0; i < image.getWidth(); i++) {
        if (image.getRGB(i, j) != -16777216) {
            image.setRGB(i, j, -1);
return image;
...
BufferedImageboostBufferedImagePerformance(BufferedImage image, boolean translucent)
boost Buffered Image Performance
GraphicsConfiguration gfx_config = GraphicsEnvironment.getLocalGraphicsEnvironment()
        .getDefaultScreenDevice().getDefaultConfiguration();
if (image.getColorModel().equals(gfx_config.getColorModel()))
    return image;
BufferedImage newImage;
if (translucent) {
    newImage = gfx_config.createCompatibleImage(image.getWidth(), image.getHeight(),
            Transparency.TRANSLUCENT);
...
MapbuildColorStatisticsOfImage(BufferedImage image)
Builds a statistical map with all found colors as keys within a given image.
Map<Integer, Integer> colorStatistics = new HashMap<Integer, Integer>();
for (int i = 0; i < image.getWidth(); i++) {
    for (int j = 0; j < image.getHeight(); j++) {
        int rgb = image.getRGB(i, j);
        Integer counter = (Integer) colorStatistics.get(rgb);
        if (counter == null) {
            counter = 0;
        counter++;
        colorStatistics.put(new Integer(rgb), counter);
return colorStatistics;
Polygon[]buildingCoordinatesInImage(BufferedImage imageSection)
building Coordinates In Image
int[][] pixels = pixelsFromBufferedImage(imageSection);
List<Point> bluePointList = new ArrayList<>();
List<Polygon> buildings = new ArrayList<>();
for (int x = 0; x < pixels.length; x++) {
    for (int y = 0; y < pixels.length; y++) {
        int px = pixels[x][y];
        int blue = (int) (px & 0xFF);
        if (blue == 255) { 
...
int[][]buildPixelAverages(BufferedImage a, Rectangle[] sectors)
build Pixel Averages
WritableRaster raster = a.getRaster();
int[][] result = new int[sectors.length][];
for (int s = 0; s < sectors.length; s++) {
    Rectangle sector = sectors[s];
    int[] total = new int[4];
    int[] pixel = new int[4];
    for (int x = sector.x; x < sector.x + sector.width; x++) {
        for (int y = sector.y; y < sector.y + sector.height; y++) {
...
Rectangle[]buildSectors(BufferedImage a, int sqrtSectors)
build Sectors
int rows = sqrtSectors;
int columns = sqrtSectors;
int sectorWidth = a.getWidth() / columns;
int sectorHeight = a.getHeight() / columns;
Rectangle[] sectors = new Rectangle[sqrtSectors * sqrtSectors];
for (int x = 0; x < columns; x++) {
    for (int y = 0; y < rows; y++) {
        int sectorStartX = x * sectorWidth;
...
BufferedImagecascadeHorizontal(final BufferedImage... images)
cascade Horizontal
if (images.length == 0) {
    return null;
if (images.length == 1) {
    return images[0];
int height = images[0].getHeight();
int width = 0;
...