Example usage for java.awt.image BufferedImage getMinX

List of usage examples for java.awt.image BufferedImage getMinX

Introduction

In this page you can find the example usage for java.awt.image BufferedImage getMinX.

Prototype

public int getMinX() 

Source Link

Document

Returns the minimum x coordinate of this BufferedImage .

Usage

From source file:net.cloudkit.relaxation.CaptchaTest.java

public static void clearNoise(BufferedImage image) {
    final int width = image.getWidth();
    final int height = image.getHeight();

    /*/*from  w  w w. ja  va  2  s .  co  m*/
    for (int x = 0; x < width; x++) {
    for (int y = 0; y < height; y++) {
        image.setRGB(x, y, Color.WHITE.getRGB());
    }
    }
    */
    for (int x = image.getMinX(); x < width; x++) {
        for (int y = image.getMinY(); y < height; y++) {

            int point = image.getRGB(x, y);

            // 
            int top = (y > 0) ? image.getRGB(x, y - 1) : -1;
            // ?
            int right = (x < width - 1) ? image.getRGB(x + 1, y) : -1;
            // 
            int bottom = (y < height - 1) ? image.getRGB(x, y + 1) : -1;
            // 
            int left = (x > 0) ? image.getRGB(x - 1, y) : -1;
            // ?
            int topRight = ((x < width - 1) && (y > 0)) ? image.getRGB(x + 1, y - 1) : -1;
            // 
            int topLeft = ((x > 0) && (y > 0)) ? image.getRGB(x - 1, y - 1) : -1;
            // ?
            int bottomRight = ((x < width - 1) && (y < height - 1)) ? image.getRGB(x + 1, y + 1) : -1;
            // 
            int bottomLeft = ((x > 0) && (y < height - 1)) ? image.getRGB(x - 1, y + 1) : -1;

            int i = 0;
            i = (top != -1) ? i + 1 : i;
            i = (right != -1) ? i + 1 : i;
            i = (bottom != -1) ? i + 1 : i;
            i = (left != -1) ? i + 1 : i;

            i = (topRight != -1) ? i + 1 : i;
            i = (topLeft != -1) ? i + 1 : i;
            i = (bottomRight != -1) ? i + 1 : i;
            i = (bottomLeft != -1) ? i + 1 : i;

            // System.out.println("i:" + i + ", top:" + top + ", right:" + right + ", bottom:" + bottom + ", left:" + left + ", topRight:" + topRight + ", topLeft:" + topLeft + ", bottomRight:" + bottomRight + ", bottomLeft:" + bottomLeft);
            if (i < 5) {
                image.setRGB(x, y, Color.WHITE.getRGB());
            }

            /*
            int leftNearby = 0;
            if(left != -1) {
            int secondLeft = (x > 1) ? image.getRGB(x - 2, y) : -1;
            int threeLeft = (x > 2) ? image.getRGB(x - 3, y) : -1;
                    
            leftNearby = ((left == -1) ? 0 : 1) + ((secondLeft == -1) ? 0 : 1) + ((threeLeft == -1) ? 0 : 1);
            }
                    
            int rightNearby = 0;
            if(right != -1) {
            int secondRight = (x + 1 < width - 1) ? image.getRGB(x + 2, y) : -1;
            int threeRight = (x + 2 < width - 1) ? image.getRGB(x + 3, y) : -1;
                    
            rightNearby = ((right == -1) ? 0 : 1) + ((secondRight == -1) ? 0 : 1) + ((threeRight == -1) ? 0 : 1);
            }
                    
            int topNearby = 0;
            if(top != -1) {
            int secondTop = (y > 1) ? image.getRGB(x, y - 2) : -1;
            int threeTop = (y > 2) ? image.getRGB(x, y - 3) : -1;
                    
            topNearby = ((top == -1) ? 0 : 1) + ((secondTop == -1) ? 0 : 1) + ((threeTop == -1) ? 0 : 1);
            }
                    
            int bottomNearby = 0;
            if(bottom != -1) {
            int secondBottom = (y + 1 < height - 1) ? image.getRGB(x, y + 2) : -1;
            int threeBottom = (y + 2 < height - 1) ? image.getRGB(x, y + 3) : -1;
                    
            bottomNearby = ((bottom == -1) ? 0 : 1) + ((secondBottom == -1) ? 0 : 1) + ((threeBottom == -1) ? 0 : 0);
            }
                    
            System.out.println(leftNearby + " " + rightNearby + " " + topNearby + " " + bottomNearby);
            if (leftNearby != 2 && rightNearby != 2 && topNearby != 2 && bottomNearby != 2) {
            image.setRGB(x, y, Color.WHITE.getRGB());
            }
            */

            /*
            System.out.println(point - top);
            System.out.println(point - right);
            System.out.println(point - bottom);
            System.out.println(point - left);
            System.out.println(point - topRight);
            System.out.println(point - topLeft);
            System.out.println(point - bottomRight);
            System.out.println(point - bottomLeft);
            */

            // if (point != top && point != right && point != bottom && point != left && point != topRight && point != topLeft && point != bottomRight && point != bottomLeft) {
            //     image.setRGB(x, y, Color.WHITE.getRGB());
            // }

            /*
            Color color = new Color(image.getRGB(x, y));
            if((color.getBlue() < 120) || ((color.getRed() + color.getGreen() + color.getBlue()) < 50)) { //
            image.setRGB(x, y, Color.WHITE.getRGB());
            } else if((color.getRed() + color.getGreen() + color.getBlue()) < 400) {
            image.setRGB(x, y, Color.BLACK.getRGB());
            }
            */

            Color color = new Color(image.getRGB(x, y));
            if ((color.getRed() + color.getGreen() + color.getBlue()) < 600) {
                image.setRGB(x, y, Color.BLACK.getRGB());
            } else {
                image.setRGB(x, y, Color.WHITE.getRGB());
            }
        }
    }

}

From source file:cn.z.Ocr5.java

public static BufferedImage removeBackgroud(File picFile) throws Exception {

    BufferedImage img = ImageIO.read(picFile);
    final int width = img.getWidth();
    final int height = img.getHeight();

    // int blackThreshold = 300;

    // img.getMinX() img.getMinY()
    for (int x = img.getMinX(); x < width; x++) {
        for (int y = img.getMinY(); y < height; y++) {

            Color color = new Color(img.getRGB(x, y));
            if ((color.getBlue() < 120) || ((color.getRed() + color.getGreen() + color.getBlue()) < 50)) { //
                img.setRGB(x, y, Color.WHITE.getRGB());
            } else if ((color.getRed() + color.getGreen() + color.getBlue()) < 400) {
                img.setRGB(x, y, Color.BLACK.getRGB());
            }//from w  w w . j  a  v a2  s . c  o m

            int nearly = 0;
            int vertical = 0;
            int horizontal = 0;

            if (x > 0) {
                Color leftColor = new Color(img.getRGB(x - 1, y));
                if ((leftColor.getRed() + leftColor.getGreen() + leftColor.getBlue()) < 400) {
                    nearly++;
                    horizontal++;
                }
            }
            if (x < width - 1) {
                Color rightColor = new Color(img.getRGB(x + 1, y));
                if ((rightColor.getRed() + rightColor.getGreen() + rightColor.getBlue()) < 400) {
                    nearly++;
                    horizontal++;
                }
            }
            if (y > 0) {
                Color topColor = new Color(img.getRGB(x, y - 1));
                if ((topColor.getRed() + topColor.getGreen() + topColor.getBlue()) < 400) {
                    nearly++;
                    vertical++;
                }
            }
            if (y < height - 1) {
                Color bottomColor = new Color(img.getRGB(x, y + 1));
                if ((bottomColor.getRed() + bottomColor.getGreen() + bottomColor.getBlue()) < 400) {
                    nearly++;
                    vertical++;
                }
            }

            if (x > 0 && y > 0) {
                Color leftTopColor = new Color(img.getRGB(x - 1, y - 1));
                if ((leftTopColor.getRed() + leftTopColor.getGreen() + leftTopColor.getBlue()) < 400) {
                    nearly++;
                }
            }
            if (x < width - 1 && y < height - 1) {
                Color rightBottomColor = new Color(img.getRGB(x + 1, y + 1));
                if ((rightBottomColor.getRed() + rightBottomColor.getGreen()
                        + rightBottomColor.getBlue()) < 400) {
                    nearly++;
                }
            }
            if (x < width - 1 && y > 0) {
                Color rightTopColor = new Color(img.getRGB(x + 1, y - 1));
                if ((rightTopColor.getRed() + rightTopColor.getGreen() + rightTopColor.getBlue()) < 400) {
                    nearly++;
                }
            }
            if (x > 0 && y < height - 1) {
                Color leftBottomColor = new Color(img.getRGB(x - 1, y + 1));
                if ((leftBottomColor.getRed() + leftBottomColor.getGreen() + leftBottomColor.getBlue()) < 400) {
                    nearly++;
                }
            }

            if (nearly < 2) {
                img.setRGB(x, y, Color.WHITE.getRGB());
            }
            /*
            if (horizontal < 1 && vertical > 0) {
            img.setRGB(x, y, Color.WHITE.getRGB());
            }
            if (horizontal > 0 && vertical < 1) {
            img.setRGB(x, y, Color.WHITE.getRGB());
            }
            */

            /*
            if (isWhite(img.getRGB(x, y), whiteThreshold) == 1) {
            img.setRGB(x, y, Color.WHITE.getRGB());
            } else {
            img.setRGB(x, y, Color.BLACK.getRGB());
            }
                    
                    
            if (getColorBright(img.getRGB(x, y)) < 100) {
            int count = isBlack(img.getRGB(x - 1, y), blackThreshold) + isBlack(img.getRGB(x + 1, y), blackThreshold) + isBlack(img.getRGB(x, y - 1), blackThreshold) + isBlack(img.getRGB(x, y + 1), blackThreshold) + isBlack(img.getRGB(x + 1, y + 1), blackThreshold) + isBlack(img.getRGB(x - 1, y - 1), blackThreshold) + isBlack(img.getRGB(x + 1, y -1 ), blackThreshold) + isBlack(img.getRGB(x - 1, y + 1), blackThreshold);
            System.out.println(count);
            if (count < 2) {
                img.setRGB(x, y, Color.WHITE.getRGB());
            }
            //     img.setRGB(x, y, Color.WHITE.getRGB());
            }
            */

            //                if(getColorBright(img.getRGB(x, y)) > 600) {
            //                    img.setRGB(x, y, Color.WHITE.getRGB());
            //                } else {
            //                    /*
            //                    // ?Graphics2D
            //                    Graphics2D g2d = img.createGraphics();
            //                    // ?
            //                    // 1.0f? 0-1.0????
            //                    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));
            //                    // 
            //                    g2d.setColor(new Color(255,0,0));
            //                    g2d.setStroke(new BasicStroke(1));
            //                    // g2d.draw
            //                    // 
            //                    // ? ?
            //                    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
            //                    g2d.dispose();
            //                    */
            //
            //                    img.setRGB(x, y, Color.BLACK.getRGB());
            //                    /*
            //                    System.out.println(getColorBright(img.getRGB(x, y)) + ":");
            //                    System.out.println(getColorBright(img.getRGB(x + 1, y)) + "-" + getColorBright(img.getRGB(x + 1, y + 1)) + "-" + getColorBright(img.getRGB(x, y + 1)));
            //                    System.out.println(getColorBright(img.getRGB(x - 1, y)) + "-" + getColorBright(img.getRGB(x - 1, y - 1)) + "-" + getColorBright(img.getRGB(x, y - 1)));
            //                    System.out.println(getColorBright(img.getRGB(x - 1, y + 1)) + "-" + getColorBright(img.getRGB(x + 1, y - 1)));
            //                    */
            //
            //                    /*
            //                    int i = 0;
            //                    i = ((x < width - 1) && getColorBright(img.getRGB(x + 1, y)) < 30)? i + 1 : i;
            //                    i = ((x < width - 1) && (y < height - 1) && getColorBright(img.getRGB(x + 1, y + 1)) < 30)? i + 1 : i;
            //                    i = ((y < height - 1) && getColorBright(img.getRGB(x, y + 1)) < 30)? i + 1 : i;
            //                    i = ((x > 0) && getColorBright(img.getRGB(x - 1, y)) < 30)? i + 1 : i;
            //                    i = ((x > 0) && (y > 0) && getColorBright(img.getRGB(x - 1, y - 1)) < 30)? i + 1 : i;
            //                    i = ((y > 0) && getColorBright(img.getRGB(x, y - 1)) < 30)? i + 1 : i;
            //                    i = ((x < width - 1) && (y > 0) && getColorBright(img.getRGB(x + 1, y - 1)) < 30)? i + 1 : i;
            //                    i = ((x > 0) && (y < height - 1) && getColorBright(img.getRGB(x - 1, y + 1)) < 30)? i + 1 : i;
            //
            //                    if(i > 1) {
            //                        img.setRGB(x, y, Color.BLACK.getRGB());
            //                    } else {
            //                        img.setRGB(x, y, Color.WHITE.getRGB());
            //                    }
            //                    */
            //                }

            /*
            int i = 0;
            i = (getColorBright(img.getRGB(x + 1, y)) == 0)? i + 1 : i;
            i = (getColorBright(img.getRGB(x + 1, y + 1)) == 0)? i + 1 : i;
            i = (getColorBright(img.getRGB(x, y + 1)) == 0)? i + 1 : i;
            i = (getColorBright(img.getRGB(x - 1, y)) == 0)? i + 1 : i;
            i = (getColorBright(img.getRGB(x - 1, y - 1)) == 0)? i + 1 : i;
            i = (getColorBright(img.getRGB(x, y - 1)) == 0)? i + 1 : i;
                    
            System.out.println(getColorBright(img.getRGB(x, y)) + ":");
            System.out.println(getColorBright(img.getRGB(x + 1, y)) + "-" + getColorBright(img.getRGB(x + 1, y + 1)) + "-" + getColorBright(img.getRGB(x, y + 1)));
            System.out.println(getColorBright(img.getRGB(x - 1, y)) + "-" + getColorBright(img.getRGB(x - 1, y - 1)) + "-" + getColorBright(img.getRGB(x, y - 1)));
            System.out.println(getColorBright(img.getRGB(x - 1, y + 1)) + "-" + getColorBright(img.getRGB(x + 1, y - 1)));
            if(getColorBright(img.getRGB(x, y)) == 0 &&  i < 3) {
            img.setRGB(x, y, Color.WHITE.getRGB());
            }
            */

            /*
            // ?for????
            // ??object
            Object data = img.getRaster().getDataElements(x, y, null);
            int red = img.getColorModel().getRed(data);
            int blue = img.getColorModel().getBlue(data);
            int green = img.getColorModel().getGreen(data);
            System.out.println((red + blue + green) + "-" + getColorBright(img.getRGB(x, y)));
            red = (red * 3 + green * 6 + blue * 1)/10;
            green = red;
            blue = green;
                    
            // r?g?b?rgbbufferedImage????rgbrgb8388608?255*255*255?16777216
            int rgb = (red * 256 + green) * 256 + blue;
            if(rgb > 8388608) {
            rgb = rgb - 16777216;
            }
            // rgb
            img.setRGB(x, y, rgb);
            */

        }
    }
    // img = img.getSubimage(1, 1, img.getWidth() - 2, img.getHeight() - 2);
    return img;
}

From source file:org.geolatte.maprenderer.sld.graphics.ExternalGraphicsRepository.java

private BufferedImage rotate(BufferedImage img, float rotation) {
    AffineTransform tx = new AffineTransform();
    //determine center point of image
    int sx = img.getMinX() + img.getWidth() / 2;
    int sy = img.getMinY() + img.getHeight() / 2;
    double theta = Math.toRadians(rotation);
    tx.rotate(theta, sx, sy);/*  ww w.  j a va2s .c om*/
    AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
    return op.filter(img, null);
}

From source file:net.cloudkit.relaxation.VerifyImage.java

public void clearNoise(BufferedImage image) {
    /*/*from ww w. j  a  va  2  s  . c om*/
    int w = image.getWidth();
    int h = image.getHeight();
            
    int p1;
    int p2;
    for (p1 = 0; p1 < w; ++p1) {
    for (p2 = 0; p2 < h; ++p2) {
        if (p1 == 0 || p2 == 0 || p1 == w - 1 || p2 == h - 1) {
            image.setRGB(p1, p2, Color.WHITE.getRGB());
        }
    }
    }
            
    for (int x = 0; x < w; ++x) {
    for (int y = 0; y < h; ++y) {
        p1 = x == 0 ? 255 : getRed(image.getRGB(x - 1, y));
        p2 = x == w - 1 ? 255 : getRed(image.getRGB(x + 1, y));
        int p3 = y == 0 ? 255 : getRed(image.getRGB(x, y - 1));
        int p4 = y == h - 1 ? 255 : getRed(image.getRGB(x, y + 1));
        int p5 = x != 0 && y != 0 ? getRed(image.getRGB(x - 1, y - 1)) : 255;
        int p6 = x != w - 1 && y != 0 ? getRed(image.getRGB(x + 1, y - 1)) : 255;
        int p7 = x != 0 && y != h - 1 ? getRed(image.getRGB(x - 1, y + 1)) : 255;
        int p8 = x != w - 1 && y != h - 1 ? getRed(image.getRGB(x + 1, y + 1)) : 255;
        if (p1 == 255 && p1 == p2 && p2 == p3 && p3 == p4 && p4 == p5 && p5 == p6 && p7 == p8) {
            image.setRGB(x, y, Color.WHITE.getRGB());
        }
    }
    }
    */

    final int width = image.getWidth();
    final int height = image.getHeight();

    // int blackThreshold = 300;

    // img.getMinX() img.getMinY()
    for (int x = image.getMinX(); x < width; x++) {
        for (int y = image.getMinY(); y < height; y++) {

            //                Color color = new Color(image.getRGB(x, y));
            //                if((color.getBlue() < 120) || ((color.getRed() + color.getGreen() + color.getBlue()) < 50)) { //
            //                    image.setRGB(x, y, Color.WHITE.getRGB());
            //                } else if((color.getRed() + color.getGreen() + color.getBlue()) < 400) {
            //                    image.setRGB(x, y, Color.BLACK.getRGB());
            //                }

            int nearly = 0;
            int vertical = 0;
            int horizontal = 0;

            if (x > 0) {
                Color leftColor = new Color(image.getRGB(x - 1, y));
                if ((leftColor.getRed() + leftColor.getGreen() + leftColor.getBlue()) < 400) {
                    nearly++;
                    horizontal++;
                }
            }
            if (x < width - 1) {
                Color rightColor = new Color(image.getRGB(x + 1, y));
                if ((rightColor.getRed() + rightColor.getGreen() + rightColor.getBlue()) < 400) {
                    nearly++;
                    horizontal++;
                }
            }
            if (y > 0) {
                Color topColor = new Color(image.getRGB(x, y - 1));
                if ((topColor.getRed() + topColor.getGreen() + topColor.getBlue()) < 400) {
                    nearly++;
                    vertical++;
                }
            }
            if (y < height - 1) {
                Color bottomColor = new Color(image.getRGB(x, y + 1));
                if ((bottomColor.getRed() + bottomColor.getGreen() + bottomColor.getBlue()) < 400) {
                    nearly++;
                    vertical++;
                }
            }

            if (x > 0 && y > 0) {
                Color leftTopColor = new Color(image.getRGB(x - 1, y - 1));
                if ((leftTopColor.getRed() + leftTopColor.getGreen() + leftTopColor.getBlue()) < 400) {
                    nearly++;
                }
            }
            if (x < width - 1 && y < height - 1) {
                Color rightBottomColor = new Color(image.getRGB(x + 1, y + 1));
                if ((rightBottomColor.getRed() + rightBottomColor.getGreen()
                        + rightBottomColor.getBlue()) < 400) {
                    nearly++;
                }
            }
            if (x < width - 1 && y > 0) {
                Color rightTopColor = new Color(image.getRGB(x + 1, y - 1));
                if ((rightTopColor.getRed() + rightTopColor.getGreen() + rightTopColor.getBlue()) < 400) {
                    nearly++;
                }
            }
            if (x > 0 && y < height - 1) {
                Color leftBottomColor = new Color(image.getRGB(x - 1, y + 1));
                if ((leftBottomColor.getRed() + leftBottomColor.getGreen() + leftBottomColor.getBlue()) < 400) {
                    nearly++;
                }
            }

            if (nearly < 2) {
                image.setRGB(x, y, Color.WHITE.getRGB());
            }

        }
    }
}

From source file:org.broad.igv.batch.CommandExecutorTest.java

@Test
public void testSnapshotsize() throws Exception {
    String filePath = TestUtils.DATA_DIR + "bam/NA12878.SLX.sample.bam";
    int numLoads = 1;

    for (int ii = 0; ii < numLoads; ii++) {
        IGV.getInstance().loadResources(Arrays.asList(new ResourceLocator(filePath)));
    }// w w w .  j  av  a 2 s.c  o m
    exec.execute("goto chr1:9,713,386-9,733,865");

    int minHeight = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight() - 150;
    int maxHeight = minHeight + 200;

    String outFileName = minHeight + ".png";

    exec.execute("maxpanelheight " + maxHeight);
    exec.execute("snapshot " + outFileName);

    File outputFile = new File(snapshotDir, outFileName);
    BufferedImage image = ImageIO.read(outputFile);

    assertTrue("Output image height " + image.getHeight() + " is not at least " + minHeight,
            image.getHeight() > minHeight);

    int remAlphaMask = 0x00ffffff;

    int numBlackPix = 0;
    for (int yy = image.getMinY(); yy < image.getHeight(); yy++) {
        for (int xx = image.getMinX(); xx < image.getWidth(); xx++) {
            int color = image.getRGB(xx, yy) & remAlphaMask;
            numBlackPix += color == 0 ? 1 : 0;
        }
    }

    //Just making sure we don't trivially satisfy the problem
    assertTrue(numBlackPix > 100);

    int totalPix = image.getHeight() * image.getWidth();
    assertTrue("Too much of the snapshot is black", numBlackPix < totalPix * 0.1);
}

From source file:org.deegree.securityproxy.wms.responsefilter.clipping.SimpleRasterClipper.java

private MapViewport createViewPort(BufferedImage inputImage, ReferencedEnvelope referencedBbox) {
    MapViewport viewPort = new MapViewport(referencedBbox);
    int screenX = inputImage.getMinX();
    int screenY = inputImage.getMinY();
    int screenWidth = inputImage.getWidth();
    int screenHeight = inputImage.getHeight();
    viewPort.setScreenArea(new Rectangle(screenX, screenY, screenWidth, screenHeight));
    return viewPort;
}