Example usage for java.awt Color getGreen

List of usage examples for java.awt Color getGreen

Introduction

In this page you can find the example usage for java.awt Color getGreen.

Prototype

public int getGreen() 

Source Link

Document

Returns the green component in the range 0-255 in the default sRGB space.

Usage

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;//from  ww w.  j a v  a2  s .c  om
        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: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;//  w  w  w  .j av a2  s  . c o 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:baocaoxla.xuly_compare.java

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

    for (int i = 0; i < 256; i++) {
        his[i] = 0;//  w ww.  j  a  va  2 s.  c  o m
        hisnomal[i] = 0;
        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]++;
            // hisnomal[255-(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 sum = 0;
    double sum1 = 0;
    for (int i = 0; i < 256; i++) {
        sum1 = sum1 + Math.pow(hisnomal[i] - his[i], 2) / (hisnomal[i] + his[i]);
    }
    for (int i = 0; i < 256; i++) {
        sum = sum + Math.pow(his1[i] - his[i], 2) / (his1[i] + his[i]);
    }
    int percent = (int) ((1 - sum / sum1) * 100);
    return percent;
}

From source file:main.java.whiteSocket.Bloop.java

private static int getBrightnessThreshold() {
    /**//from   ww w.ja va2s  . c  o  m
     * get average pixel brightness of white pixels whiteboard input image
     * NOTE: lower brightness value = darker the pixel
     * using relative luminance
     * https://en.wikipedia.org/wiki/Relative_luminance
     * 
     * rough threshold value = 30% less than average of darkest corner
     * assumes average corner spans 60% brightness (+/-30%)
     */

    Color color = null;
    float brightness = 0;
    int r, g, b;
    int count = 0;
    int avg_UL, avg_UR, avg_LL, avg_LR;
    float totalBrightness = 0;

    for (int row = 0; row < 10; row++) { //   UL
        for (int col = 0; col < 10; col++) {
            count++;
            color = new Color(sketch.getRGB(col, row));
            r = color.getRed();
            g = color.getGreen();
            b = color.getBlue();
            brightness = (float) (0.2126 * r + 0.7152 * g + 0.0722 * b);
            totalBrightness += brightness;
        }
    }
    avg_UL = (int) (totalBrightness / count);

    totalBrightness = 0;
    count = 0;
    for (int row = 0; row < 10; row++) { //  UR
        for (int col = sketch.getWidth() - 10; col < sketch.getWidth(); col++) {
            count++;
            color = new Color(sketch.getRGB(col, row));
            r = color.getRed();
            g = color.getGreen();
            b = color.getBlue();
            brightness = (float) (0.2126 * r + 0.7152 * g + 0.0722 * b);
            totalBrightness += brightness;
        }
    }
    avg_UR = (int) (totalBrightness / count);

    totalBrightness = 0;
    count = 0;
    for (int row = sketch.getHeight() - 10; row < sketch.getHeight(); row++) { //   LL
        for (int col = 0; col < 10; col++) {
            count++;
            color = new Color(sketch.getRGB(col, row));
            r = color.getRed();
            g = color.getGreen();
            b = color.getBlue();
            brightness = (float) (0.2126 * r + 0.7152 * g + 0.0722 * b);
            totalBrightness += brightness;
        }
    }
    avg_LL = (int) (totalBrightness / count);

    totalBrightness = 0;
    count = 0;
    for (int row = sketch.getHeight() - 10; row < sketch.getHeight(); row++) { //   LR
        for (int col = sketch.getWidth() - 10; col < sketch.getWidth(); col++) {
            count++;
            color = new Color(sketch.getRGB(col, row));
            r = color.getRed();
            g = color.getGreen();
            b = color.getBlue();
            brightness = (float) (0.2126 * r + 0.7152 * g + 0.0722 * b);
            totalBrightness += brightness;
        }
    }
    avg_LR = (int) (totalBrightness / count);

    int threshold = (int) (0.7 * Math.min(Math.min(avg_LL, avg_LR), Math.min(avg_UL, avg_UR)));

    //      System.out.println("\nthreshold = "+threshold);

    return threshold;
}

From source file:org.neo4art.colour.service.ImageDefaultManager.java

/**
 * /*from  w  w  w .ja  v  a2 s  .co m*/
 * @param color
 * @return
 */
public String getClosestColourName(Color color) {
    Colour colour = getClosestColour(color.getRed(), color.getGreen(), color.getBlue());

    if (colour != null) {
        return colour.getName();
    }

    return null;
}

From source file:baocaoxla.xuly_compare.java

public int Correlation(BufferedImage image, BufferedImage imgcompare) {
    //BufferedImage img=new BufferedImage(image.getWidth(),get, imageType)
    int[] his = new int[256];
    int[] his1 = new int[256];

    for (int i = 0; i < 256; i++) {
        his[i] = 0;//from w w w. j  a va  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 sumhis = 0;
    double sumhis1 = 0;

    for (int i = 0; i < 256; i++) {
        sumhis = sumhis + his[i];
        sumhis1 = sumhis1 + his1[i];
    }
    double tu = 0;
    double mau1 = 0;
    double mau2 = 0;
    for (int i = 0; i < 256; i++) {
        tu = tu + (his[i] - sumhis / 256) * (his1[i] - sumhis1 / 256);
        mau1 = mau1 + Math.pow((his[i] - sumhis / 256), 2);
        mau2 = mau2 + Math.pow((his1[i] - sumhis1 / 256), 2);
    }
    double mau = Math.sqrt(mau1 * mau2);
    int compare = (int) (((tu / mau) + 1) * 50);

    return compare;
}

From source file:playground.sergioo.workplaceCapacities2012.gui.ClustersPanel.java

public ClustersPanel(ClustersWindow window, List<CentroidCluster<PointPerson>> clusters) {
    super();// ww  w  . j a v a2  s.  c  o  m
    this.window = window;
    addLayer(new Layer(new AxisPainter(24 * 3600, 18 * 3600, 0, 6 * 3600, 3600, 3600, Color.DARK_GRAY)));
    PointsPainter pointsPainter = new PointsPainter();
    float i = 0;
    for (org.apache.commons.math3.ml.clustering.Cluster<PointPerson> cluster : clusters) {
        //Color color = new Color((float)(Math.random()*0.5), (float)(Math.random()*0.5), (float)(Math.random()*0.5), 0.3f);
        float p = (i + 0.5f) / clusters.size();
        Color color = JetColor.getJetColor(p);
        color = new Color(color.getRed(), color.getGreen(), color.getBlue(), 50);
        PointsPersonPainter ppPainter = new PointsPersonPainter(color);
        ppPainter.setWeightedPoints(cluster.getPoints());
        addLayer(new Layer(ppPainter));
        PointPerson center = cluster.getPoints().get(0).centroidOf(cluster.getPoints());
        pointsPainter.addPoint(new CoordImpl(center.getElement(0), center.getElement(1)));
        i++;
    }
    addLayer(new Layer(pointsPainter));
    this.setBackground(Color.WHITE);
    calculateBoundaries();
    super.setPreferredSize(Toolkit.getDefaultToolkit().getScreenSize().width,
            Toolkit.getDefaultToolkit().getScreenSize().height);
    addMouseListener(this);
    addMouseMotionListener(this);
    addMouseWheelListener(this);
    addKeyListener(this);
    setFocusable(true);
}

From source file:org.emonocot.portal.view.Functions.java

private static Map<String, String> getColorMap(Set<String> categories) {
    int numberOfCategories = categories.size();
    float increment = 0.5f / (numberOfCategories / 5);
    Map<String, String> colorMap = new HashMap<String, String>();

    int i = 0;//w  ww.ja v  a 2 s . co m
    for (String category : categories) {
        Color baseColor = baseColors[i % 5];
        int offset = i / 5;
        if (offset > 0) {
            float hsbVals[] = Color.RGBtoHSB(baseColor.getRed(), baseColor.getGreen(), baseColor.getBlue(),
                    null);
            Color highlight = Color.getHSBColor(hsbVals[0], hsbVals[1], offset * increment * (1f + hsbVals[2]));
            colorMap.put(category, String.format("#%06X", (0xFFFFFF & highlight.getRGB())));
        } else {
            colorMap.put(category, String.format("#%06X", (0xFFFFFF & baseColor.getRGB())));
        }
        i++;
    }

    return colorMap;
}

From source file:dk.dma.msinm.web.wms.WmsProxyServlet.java

/**
 * Masks out white colour//from  ww w  . j av  a2  s.  c o m
 * @param image the image to mask out
 * @return the resulting image
 */
private BufferedImage transformWhiteToTransparent(BufferedImage image) {

    BufferedImage dest = image;
    if (image.getType() != BufferedImage.TYPE_INT_ARGB) {
        dest = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = dest.createGraphics();
        g2.drawImage(image, 0, 0, null);
        g2.dispose();

        image.flush();
    }

    // Mask out the white pixels
    final int width = image.getWidth();
    int[] imgData = new int[width];

    for (int y = 0; y < dest.getHeight(); y++) {
        // fetch a line of data from each image
        dest.getRGB(0, y, width, 1, imgData, 0, 1);
        // apply the mask
        for (int x = 0; x < width; x++) {
            for (Color col : MASKED_COLORS) {
                int colDist = Math.abs(col.getRed() - (imgData[x] >> 16 & 0x000000FF))
                        + Math.abs(col.getGreen() - (imgData[x] >> 8 & 0x000000FF))
                        + Math.abs(col.getBlue() - (imgData[x] & 0x000000FF));
                if (colDist <= COLOR_DIST) {
                    imgData[x] = 0x00FFFFFF & imgData[x];
                }
            }
        }
        // replace the data
        dest.setRGB(0, y, width, 1, imgData, 0, 1);
    }
    return dest;
}

From source file:org.springframework.boot.ImageBanner.java

private int getLuminance(Color color, boolean inverse) {
    double luminance = 0.0;
    luminance += getLuminance(color.getRed(), inverse, RGB_WEIGHT[0]);
    luminance += getLuminance(color.getGreen(), inverse, RGB_WEIGHT[1]);
    luminance += getLuminance(color.getBlue(), inverse, RGB_WEIGHT[2]);
    return (int) Math.ceil((luminance / 0xFF) * 100);
}