Example usage for java.awt.image BufferedImage getRGB

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

Introduction

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

Prototype

public int getRGB(int x, int y) 

Source Link

Document

Returns an integer pixel in the default RGB color model (TYPE_INT_ARGB) and default sRGB colorspace.

Usage

From source file:org.iish.visualmets.services.ImageTransformation.java

/**
 * Returns a 180 degrees rotated image//from  ww w .  j  a  v  a  2  s  . co m
 *
 * @param bi image
 * @return a rotated image
 */
private BufferedImage RotateImage180Degrees(BufferedImage bi) {
    int width = bi.getWidth();
    int height = bi.getHeight();

    BufferedImage biFlip = new BufferedImage(width, height, bi.getType());

    for (int i = 0; i < width; i++)
        for (int j = 0; j < height; j++) {
            biFlip.setRGB(width - 1 - i, height - 1 - j, bi.getRGB(i, j));
        }

    return biFlip;
}

From source file:org.geotools.data.wms.test.LocalGeoServerOnlineTest.java

/**
 * Check GetMap request functionality in the provided CRS.
 * <p>//from w  w w  .  j a va  2 s  .  c o  m
 * Attempt is made to request the entire image.
 * 
 * @param wms
 * @param layer
 * @param crs
 */
private void checkGetMap(WebMapServer wms, Layer layer, CoordinateReferenceSystem crs) throws Exception {

    layer.clearCache();
    CRSEnvelope latLon = layer.getLatLonBoundingBox();
    GeneralEnvelope envelope = wms.getEnvelope(layer, crs);
    assertFalse(envelope.isEmpty() || envelope.isNull() || envelope.isInfinite());
    assertNotNull("Envelope " + CRS.toSRS(crs), envelope);

    GetMapRequest getMap = wms.createGetMapRequest();
    OperationType operationType = wms.getCapabilities().getRequest().getGetMap();

    getMap.addLayer(layer);
    String version = wms.getCapabilities().getVersion();

    getMap.setBBox(envelope);

    Properties properties = getMap.getProperties();
    String srs = null;
    if (properties.containsKey("SRS")) {
        srs = properties.getProperty("SRS");
    } else if (properties.containsKey("CRS")) {
        srs = properties.getProperty("CRS");
    }
    assertNotNull("setBBox supplied SRS information", srs);
    String expectedSRS = CRS.toSRS(envelope.getCoordinateReferenceSystem());
    assertEquals("srs matches CRS.toSRS", expectedSRS, srs);

    assertTrue("cite authority:" + srs, srs.contains("CRS") || srs.contains("EPSG"));

    //getMap.setSRS( srs );

    String format = format(operationType, "jpeg");
    getMap.setFormat(format);
    getMap.setDimensions(500, 500);

    URL url = getMap.getFinalURL();
    GetMapResponse response = wms.issueRequest(getMap);
    assertEquals("image/jpeg", response.getContentType());

    InputStream stream = response.getInputStream();
    BufferedImage image = ImageIO.read(stream);
    assertNotNull("jpeg", image);
    assertEquals(500, image.getWidth());
    assertEquals(500, image.getHeight());

    int rgb = image.getRGB(70, 420);
    Color sample = new Color(rgb);
    boolean forceXY = Boolean.getBoolean(GeoTools.FORCE_LONGITUDE_FIRST_AXIS_ORDER);
    String context = "srs=" + srs + " forceXY=" + forceXY + " Version=" + version;
    if (Color.WHITE.equals(sample)) {
        System.out.println("FAIL: " + context + ": GetMap BBOX=" + envelope);
        System.out.println("--> " + url);
        fail(context + ": GetMap BBOX=" + envelope);
    } else {
        //System.out.println("PASS: "+ context+": GetMap BBOX=" + bbox);
    }
}

From source file:baocaoxla.xuly_compare.java

public ChartPanel displayhistogram(BufferedImage image) {

    HistogramDataset dataset = new HistogramDataset();

    final int w = image.getWidth();
    final int h = image.getHeight();
    double[] r = new double[w * h];
    double[] g = new double[w * h];
    double[] b = new double[w * h];
    int dem = 0;/*  w w  w  .j  av a 2 s . c  o m*/
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            Color c = new Color(image.getRGB(j, i));
            r[dem] = c.getRed();
            g[dem] = c.getGreen();
            b[dem] = c.getBlue();
            dem++;
        }
    }
    //r = raster.getSamples(0, 0, w, h, 0, r);
    dataset.addSeries("Red", r, 256);
    //r = raster.getSamples(0, 0, w, h, 1, r);
    dataset.addSeries("Green", g, 256);
    // r = raster.getSamples(0, 0, w, h, 2, r);
    dataset.addSeries("Blue", b, 256);
    // chart
    JFreeChart chart = ChartFactory.createHistogram("Histogram", "Value", "Count", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    ChartPanel panel = new ChartPanel(chart);
    return panel;

}

From source file:com.tascape.qa.th.android.driver.AdbDevice.java

private boolean bufferedImagesEqual(BufferedImage img1, BufferedImage img2) {
    if (img1.getWidth() != img2.getWidth() || img1.getHeight() != img2.getHeight()) {
        return false;
    }//from  ww  w .  ja  v  a  2s  . c  o  m

    boolean equal = true;
    for (int x = 100; x < img1.getWidth() - 100; x++) {
        for (int y = 100; y < img1.getHeight() - 100; y++) {
            if (img1.getRGB(x, y) != img2.getRGB(x, y)) {
                equal = false;
            }
        }
    }
    return equal;
}

From source file:fr.gael.drb.cortex.topic.sentinel3.jai.operator.QuicklookSlstrRIF.java

/**
 * Compute the natural color QL from passed images. This method only 
 * assembles provided images as red/green/blue 8 bits channels.
 * @param red red channel image// www .j a  va2  s  .c o m
 * @param green green channel image
 * @param blue blue channel image
 * @return the assembled image.
 */
private RenderedImage naturalColors(Raster red, PixelCorrection rc, Raster green, PixelCorrection gc,
        Raster blue, PixelCorrection bc) {

    BufferedImage bred = toGrayScale(red, rc, false, false);
    BufferedImage bgreen = toGrayScale(green, gc, false, false);
    BufferedImage bblue = toGrayScale(blue, bc, false, false);

    BufferedImage quicklook = new BufferedImage(red.getWidth(), red.getHeight(), BufferedImage.TYPE_INT_RGB);

    for (int j = 0; j < red.getHeight(); j++) {
        for (int i = 0; i < red.getWidth(); i++) {
            int cred = new Color(bred.getRGB(i, j)).getRed();
            int cgreen = new Color(bgreen.getRGB(i, j)).getGreen();
            int cblue = new Color(bblue.getRGB(i, j)).getBlue();

            quicklook.setRGB(i, j, new Color(cred, cgreen, cblue).getRGB());
        }
    }

    return quicklook;
}

From source file:baocaoxla.xuly_compare.java

public int intersection(BufferedImage image, BufferedImage imgcompare) {
    int[] his = new int[256];
    int[] his1 = new int[256];

    for (int i = 0; i < 256; i++) {
        his[i] = 0;/*w w  w.  jav a 2s  .  co  m*/
        his1[i] = 0;

    }
    int width = image.getWidth();
    int height = image.getHeight();
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            Color c = new Color(image.getRGB(j, i));
            his[(c.getRed() + c.getGreen() + c.getBlue()) / 3]++;

        }
    }
    int width1 = imgcompare.getWidth();
    int height1 = imgcompare.getHeight();
    for (int i = 0; i < height1; i++) {
        for (int j = 0; j < width1; j++) {
            Color c = new Color(imgcompare.getRGB(j, i));
            his1[(c.getRed() + c.getGreen() + c.getBlue()) / 3]++;
        }
    }
    double summin = 0;
    double sumhis = 0;

    for (int i = 0; i < 256; i++) {
        summin = summin + Math.min(his[i], his1[i]);
        sumhis = sumhis + his[i];
    }
    int percentred = (int) ((summin / sumhis) * 100);
    return percentred;
}

From source file:app.springapp.ImageConverter.java

public int getBlockValue(int x1, int y1, int n, boolean flag) {

    BufferedImage im;
    if (flag) {// w ww  . j  a va  2  s  .c  o m
        im = new_image;

    } else {
        im = org_image;
    }

    int x2 = getX(x1, y1, n);
    int y2 = getY(x1, y1, n);

    int sum = 0;
    int i = x1, j = y1;

    while (i != x2 || j != y2) {

        int rgb = im.getRGB(i, j);
        Color c = new Color(rgb);
        sum += c.getRed() % 2;
        sum += c.getBlue() % 2;
        sum += c.getGreen() % 2;

        if (i + 1 < org_image.getWidth()) {
            i = i + 1;

        } else {
            j++;
            i = 0;
        }

    }

    int rgb = im.getRGB(x2, y2);
    Color c = new Color(rgb);
    sum += c.getRed() % 2;
    sum += c.getBlue() % 2;
    sum += c.getGreen() % 2;

    return sum;

}

From source file:baocaoxla.xuly_compare.java

public int BHATTACHARYYA(BufferedImage image, BufferedImage imgcompare) {
    int[] his = new int[256];
    int[] his1 = new int[256];

    for (int i = 0; i < 256; i++) {
        his[i] = 0;//from   w  w  w  . ja  v a 2 s . co m
        his1[i] = 0;

    }
    int width = image.getWidth();
    int height = image.getHeight();
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            Color c = new Color(image.getRGB(j, i));
            his[(c.getRed() + c.getGreen() + c.getBlue()) / 3]++;

        }
    }
    int width1 = imgcompare.getWidth();
    int height1 = imgcompare.getHeight();
    for (int i = 0; i < height1; i++) {
        for (int j = 0; j < width1; j++) {
            Color c = new Color(imgcompare.getRGB(j, i));
            his1[(c.getRed() + c.getGreen() + c.getBlue()) / 3]++;
        }
    }
    double sumhis = 0;
    double sumhis1 = 0;
    for (int i = 0; i < 256; i++) {
        sumhis = sumhis + his[i];
        sumhis1 = sumhis1 + his1[i];
    }
    double sum = 0;
    for (int i = 0; i < 256; i++) {
        sum = sum + Math.sqrt(his[i] * his1[i]);
    }
    int percent = (int) ((1 - Math.sqrt(1 - sum / Math.sqrt(sumhis * sumhis1))) * 100);
    System.out.print(Math.sqrt(1 - sum));
    return percent;
}

From source file:org.apache.pdfbox.tools.imageio.TestImageIOUtils.java

private void checkNotBlank(String filename, BufferedImage newImage) {
    // http://stackoverflow.com/a/5253698/535646
    Set<Integer> colors = new HashSet<Integer>();
    int w = newImage.getWidth();
    int h = newImage.getHeight();
    for (int x = 0; x < w; x++) {
        for (int y = 0; y < h; y++) {
            colors.add(newImage.getRGB(x, y));
        }//from w  ww.j  a  v  a2s . c o  m
    }
    assertFalse("File '" + filename + "' has less than two colors", colors.size() < 2);
}

From source file:com.hygenics.imaging.ImageCleanup.java

public byte[] reaverage(double factor, byte[] ibytes) {
    // tone red coloring
    BufferedImage color = BufferImage(ibytes);

    if (color != null) {
        BufferedImage averaged = new BufferedImage(color.getWidth(), color.getHeight(),
                BufferedImage.TYPE_INT_RGB);

        for (int i = 0; i < color.getWidth(); i++) {
            for (int j = 0; j < color.getHeight(); j++) {
                Color c = new Color(color.getRGB(i, j));

                averaged.setRGB(i, j,/*from w  ww.  j a v a 2  s.  c o  m*/
                        new Color((int) Math.round(c.getRed() / factor), c.getGreen(), c.getBlue()).getRGB());
            }
        }

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        // convert to jpeg for compression
        try {
            // use apache to read to a buffered image with certain metadata
            // and then convert to a jpg
            ImageIO.write(averaged, "jpg", bos);
            return ibytes = bos.toByteArray();

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return ibytes;

}