List of usage examples for java.awt Color RGBtoHSB
public static float[] RGBtoHSB(int r, int g, int b, float[] hsbvals)
From source file:Utils.java
/** * Derives a color by adding the specified offsets to the base color's * hue, saturation, and brightness values. The resulting hue, saturation, * and brightness values will be contrained to be between 0 and 1. * @param base the color to which the HSV offsets will be added * @param dH the offset for hue/*from w ww . jav a 2 s . c om*/ * @param dS the offset for saturation * @param dB the offset for brightness * @return Color with modified HSV values */ public static Color deriveColorHSB(Color base, float dH, float dS, float dB) { float hsb[] = Color.RGBtoHSB(base.getRed(), base.getGreen(), base.getBlue(), null); hsb[0] += dH; hsb[1] += dS; hsb[2] += dB; return Color.getHSBColor(hsb[0] < 0 ? 0 : (hsb[0] > 1 ? 1 : hsb[0]), hsb[1] < 0 ? 0 : (hsb[1] > 1 ? 1 : hsb[1]), hsb[2] < 0 ? 0 : (hsb[2] > 1 ? 1 : hsb[2])); }
From source file:ml.hsv.java
hsv(int r, int g, int b) //convert rgb to hsv and store { Color.RGBtoHSB(r, g, b, hsv); h = hsv[0]; s = hsv[1]; v = hsv[2]; }
From source file:GeMSE.GS.Analysis.Stats.OneSampleCovariancePanel.java
public OneSampleCovariancePanel() { initComponents(); Color.RGBtoHSB(214, 217, 223, bColor); _biasCorrected = false; BiasCorrectedCB.setSelected(_biasCorrected); }
From source file:GeMSE.GS.Analysis.Stats.OneSamplePearsonsCorrelationPanel.java
public OneSamplePearsonsCorrelationPanel() { initComponents(); Color.RGBtoHSB(214, 217, 223, bColor); }
From source file:lisong_mechlab.view.graphs.WeaponColouredDrawingSupplier.java
private Color colorShift(Color aColour, int aMax, int aCurr) { float hsb[] = new float[3]; Color.RGBtoHSB(aColour.getRed(), aColour.getGreen(), aColour.getBlue(), hsb); float blend = aMax == 1 ? 1.0f : (float) aCurr / (aMax - 1); float range_min = 0.55f; float range_max = 1.0f; float saturation = (range_max - range_min) * blend + range_min; hsb[1] *= saturation;/*from w w w . ja va 2s .com*/ hsb[2] *= saturation; return new Color(Color.HSBtoRGB(hsb[0], hsb[1], hsb[2])); }
From source file:GeMSE.Visualization.ElbowPlot.java
public void Plot(ArrayList<Double[]> pvData, ArrayList<Double[]> dData, int cut) { double maxY = 0; float[] secYColor = new float[3]; Color.RGBtoHSB(153, 245, 255, secYColor); float[] priYColor = new float[3]; Color.RGBtoHSB(255, 255, 255, priYColor); float[] cutColor = new float[3]; Color.RGBtoHSB(255, 255, 0, cutColor); //create the series - add some dummy data XYSeries pvSeries = new XYSeries("Percentage of variance "); for (int i = 1; i < pvData.size(); i++) { pvSeries.add(pvData.get(i)[0], pvData.get(i)[1]); maxY = Math.max(maxY, pvData.get(i)[1]); }//from w w w . ja v a 2 s. com XYSeries dSeries = new XYSeries("Percentage of differences between slopes "); for (int i = 0; i < dData.size(); i++) dSeries.add(dData.get(i)[0], dData.get(i)[1]); XYSeries cutSeries = new XYSeries("Cut "); cutSeries.add(cut, 0.0); cutSeries.add(cut, maxY); //create the datasets XYSeriesCollection pvDataSeries = new XYSeriesCollection(); pvDataSeries.addSeries(pvSeries); XYSeriesCollection cutDataSeries = new XYSeriesCollection(); cutDataSeries.addSeries(cutSeries); XYSeriesCollection dDataSeries = new XYSeriesCollection(); dDataSeries.addSeries(dSeries); //construct the plot XYPlot plot = new XYPlot(); plot.setDataset(0, pvDataSeries); plot.setDataset(1, cutDataSeries); plot.setDataset(2, dDataSeries); // use XYSplineRenderer if you want to smooth the lines. XYLineAndShapeRenderer pvRenderer = new XYLineAndShapeRenderer(); pvRenderer.setSeriesPaint(0, Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2])); BasicStroke dstroke = new BasicStroke(2.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 1.0f, 10.0f }, 0.0f); XYLineAndShapeRenderer dRenderer = new XYLineAndShapeRenderer(); dRenderer.setSeriesPaint(0, Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2])); dRenderer.setSeriesStroke(0, dstroke); BasicStroke cutStoke = new BasicStroke(4); // use XYSplineRenderer if you want to smooth the lines. //XYSplineRenderer cutRenderer = new XYSplineRenderer(); XYLineAndShapeRenderer cutRenderer = new XYLineAndShapeRenderer(); cutRenderer.setSeriesPaint(0, Color.getHSBColor(cutColor[0], cutColor[1], cutColor[2])); cutRenderer.setSeriesStroke(0, cutStoke); plot.setRenderer(0, pvRenderer); plot.setRenderer(1, cutRenderer); plot.setRenderer(2, dRenderer); plot.setRangeAxis(0, new NumberAxis("\n\nPercentage of Variance")); plot.setRangeAxis(1, new NumberAxis("Percentage of Difference Between Slopes")); plot.setDomainAxis(new NumberAxis("Number of Clusters\n\n")); //Map the data to the appropriate axis plot.mapDatasetToRangeAxis(0, 0); plot.mapDatasetToRangeAxis(1, 0); plot.mapDatasetToRangeAxis(2, 1); float[] hsbValues = new float[3]; Color.RGBtoHSB(16, 23, 67, hsbValues); plot.setBackgroundPaint(Color.getHSBColor(hsbValues[0], hsbValues[1], hsbValues[2])); Font axisLabelFont = new Font("Dialog", Font.PLAIN, 14); Font axisTickLabelFont = new Font("Dialog", Font.PLAIN, 12); Font legendFont = new Font("Dialog", Font.PLAIN, 14); plot.setDomainGridlinePaint(Color.gray); plot.setRangeGridlinePaint(Color.gray); plot.getDomainAxis().setTickLabelPaint(Color.white); plot.getDomainAxis().setLabelPaint(Color.white); plot.getDomainAxis().setLabelFont(axisLabelFont); plot.getDomainAxis().setTickLabelFont(axisTickLabelFont); plot.getRangeAxis().setTickLabelPaint(Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2])); plot.getRangeAxis().setLabelPaint(Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2])); plot.getRangeAxis().setLabelFont(axisLabelFont); plot.getRangeAxis().setTickLabelFont(axisTickLabelFont); plot.getRangeAxis(1).setTickLabelPaint(Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2])); plot.getRangeAxis(1).setLabelPaint(Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2])); plot.getRangeAxis(1).setLabelFont(axisLabelFont); plot.getRangeAxis(1).setTickLabelFont(axisTickLabelFont); //generate the chart JFreeChart chart = new JFreeChart("\nSuggested number of clusters determined using Elbow method", getFont(), plot, true); chart.getTitle().setPaint(Color.white); chart.getLegend().setBackgroundPaint(Color.black); chart.getLegend().setItemPaint(Color.white); chart.getLegend().setPosition(RectangleEdge.BOTTOM); chart.getLegend().setItemFont(legendFont); float[] hsbValues2 = new float[3]; Color.RGBtoHSB(36, 43, 87, hsbValues2); chart.setBackgroundPaint(Color.getHSBColor(hsbValues2[0], hsbValues2[1], hsbValues2[2])); JPanel chartPanel = new ChartPanel(chart); GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); chartPanel.setPreferredSize( new java.awt.Dimension((int) Math.round((gd.getDisplayMode().getWidth() * 1.5) / 3.0), (int) Math.round((gd.getDisplayMode().getHeight() * 1.5) / 3.0))); setContentPane(chartPanel); }
From source file:GeMSE.GS.Analysis.Stats.OneSamplePCAPanel.java
public OneSamplePCAPanel() { initComponents();// w w w . j a v a 2s . c o m Color.RGBtoHSB(214, 217, 223, bColor); ButtonGroup groupA = new ButtonGroup(); groupA.add(testAreAtColsRB); groupA.add(testAreAtRowsRB); testAreAtColsRB.setSelected(true); _level = DEFAULT_LEVEL; }
From source file:ColorUtils.java
private static float[] toHSB(Color aColor) { return Color.RGBtoHSB(aColor.getRed(), aColor.getGreen(), aColor.getBlue(), null); }
From source file:Trabalho.HistogramaHSB.java
public ChartPanel criaHistograma() throws IOException { //pega a imagem BufferedImage img = pegaImagem(); //w pega a largura da imagem - h pega a altura da imagem int w = img.getWidth(); int h = img.getHeight(); //d calcula o tamanho da imagem int d = (w * h); //red, green e blue iro receber os tons de cor antigo da imagem - u vai receber o RGB da cor int red, green, blue, u; //retorna rgb no mtodo float[] hsb;//from w ww . j a v a 2 s. c om int[] vetH = new int[256]; int[] vetS = new int[256]; int[] vetB = new int[256]; float hue, sat, bri; //cAux e oldColor pegam os tons originais da imagem - newColor pega os tons aps o clculo Color oldColor; Color newColor; //for responsvel por substituir os tons antigos pelos novos; percorrem a imagem por largura e altura for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { u = img.getRGB(i, j); //u vai receber o RGB da posio i, j oldColor = new Color(u); //oldColor instanciado e recebe o valor de u //cada cor recebe o valor do tom original red = oldColor.getRed(); green = oldColor.getGreen(); blue = oldColor.getBlue(); hsb = Color.RGBtoHSB(red, green, blue, null); hue = hsb[0]; sat = hsb[1]; bri = hsb[2]; // System.out.println("RGB [" + red + "," + green + "," + blue + "] converted to HSB [" + hue + "," + sat + "," + bri + "]"); // hue = hue * 360; // int convH = Integer.valueOf(new Float(hue).intValue()); // vetH[convH]++; // // sat = sat * 100; // int convS = Integer.valueOf(new Float(sat).intValue()); // vetS[convS]++; // // bri = bri * 100; // int convB = Integer.valueOf(new Float(bri).intValue()); // vetB[convB]++; newColor = new Color(hue, sat, bri); //seta o RGB da imagem nas posies i, j pegando os valores da newColor img.setRGB(i, j, newColor.getRGB()); } } File ouptut = new File("D:\\ProjetosNetBeans\\PDI\\src\\imagens\\5.jpeg"); ImageIO.write(img, "png", ouptut); dataset = new HistogramDataset(); //pega o RGB r = raster.getSamples(0, 0, w, h, 0, r); dataset.addSeries("Red", r, 360); r = raster.getSamples(0, 0, w, h, 1, r); dataset.addSeries("Green", r, 101); r = raster.getSamples(0, 0, w, h, 2, r); dataset.addSeries("Blue", r, 101); JFreeChart chart = ChartFactory.createHistogram("Histograma", "Pixels", "Y", dataset, PlotOrientation.VERTICAL, true, true, false); //Plota as cores XYPlot plot = (XYPlot) chart.getPlot(); renderer = (XYBarRenderer) plot.getRenderer(); renderer.setBarPainter(new StandardXYBarPainter()); //vermelho, verde, azul Paint[] paintArray = { new Color(0x80ff0000, true), new Color(0x8000ff00, true), new Color(0x800000ff, true) }; //desenhando o grfico plot.setDrawingSupplier( new DefaultDrawingSupplier(paintArray, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); ChartPanel panel = new ChartPanel(chart); panel.setMouseWheelEnabled(true); return panel; }
From source file:net.sf.maltcms.chromaui.foldChangeViewer.tasks.FoldChangeViewLoaderWorker.java
@Override public void run() { ProgressHandle handle = ProgressHandleFactory.createHandle("Creating fold change plot"); try {/*from w w w. j a v a 2s. com*/ handle.setDisplayName("Loading fold change elements");//+new File(this.files.getResourceLocation()).getName()); handle.start(5); handle.progress("Reading settings", 1); RTUnit rtAxisUnit = RTUnit.valueOf(sp.getProperty("rtAxisUnit", "SECONDS")); handle.progress("Retrieving data", 2); XYShapeRenderer renderer = new XYShapeRenderer() { @Override protected Paint getPaint(XYDataset dataset, int series, int item) { double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); if (Math.abs(x) < 1.0) { Paint p = super.getPaint(dataset, series, item); if (p instanceof Color) { Color color = (Color) p; float[] values = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), new float[3]); Color hsb = new Color( Color.HSBtoRGB(values[0], (float) Math.max(0.1, values[1] - 0.9), values[2])); return new Color(hsb.getRed(), hsb.getGreen(), hsb.getBlue(), 64); } } return super.getPaint(dataset, series, item); } }; renderer.setAutoPopulateSeriesFillPaint(true); renderer.setAutoPopulateSeriesOutlinePaint(true); renderer.setBaseCreateEntities(true); handle.progress("Building plot", 3); XYPlot plot = new XYPlot(dataset, new NumberAxis("log2 fold change"), new NumberAxis("-log10 p-value"), renderer); BasicStroke dashed = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, new float[] { 5.0f }, 0.0f); ValueMarker marker = new ValueMarker(-Math.log10(0.05), Color.RED, dashed); marker.setLabel("p-value=0.05"); marker.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT); marker.setLabelOffset(new RectangleInsets(UnitType.ABSOLUTE, 0, 50, 10, 0)); marker.setLabelOffsetType(LengthAdjustmentType.EXPAND); marker.setLabelPaint(Color.LIGHT_GRAY); plot.addRangeMarker(marker); Font font1 = new Font("SansSerif", Font.PLAIN, 12); SelectionAwareXYTooltipGenerator tooltipGenerator = cvtc.getLookup() .lookup(SelectionAwareXYTooltipGenerator.class); if (tooltipGenerator == null) { tooltipGenerator = new SelectionAwareXYTooltipGenerator(tooltipGenerator) { @Override public String createSelectionAwareTooltip(XYDataset xyd, int i, int i1) { FoldChangeDataset dataset = (FoldChangeDataset) xyd; FoldChangeElement fce = dataset.getNamedElementProvider().get(i).get(i1); StringBuilder sb = new StringBuilder(); sb.append("<html>"); sb.append(fce.getPeakGroup().getMajorityDisplayName()); sb.append("<br>"); sb.append("log2 fold change="); sb.append(fce.getFoldChange()); sb.append("<br>"); sb.append("p-value="); sb.append(Math.pow(10, -fce.getPvalue())); sb.append("</html>"); return sb.toString(); } }; } tooltipGenerator.setXYToolTipGenerator(new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset xyd, int i, int i1) { Comparable comp = xyd.getSeriesKey(i); double x = xyd.getXValue(i, i1); double y = xyd.getYValue(i, i1); StringBuilder sb = new StringBuilder(); sb.append("<html>"); sb.append(comp); sb.append("<br>"); sb.append("log2 fold change="); sb.append(x); sb.append("<br>"); sb.append("p-value="); sb.append(sb.append(Math.pow(10, -y))); sb.append("</html>"); return sb.toString(); } }); plot.getRenderer().setBaseToolTipGenerator(tooltipGenerator); handle.progress("Configuring plot", 4); configurePlot(plot, rtAxisUnit); final FoldChangeViewPanel cmhp = cvtc.getLookup().lookup(FoldChangeViewPanel.class); Range domainRange = null; Range valueRange = null; if (cmhp != null) { XYPlot xyplot = cmhp.getPlot(); if (xyplot != null) { ValueAxis domain = xyplot.getDomainAxis(); domainRange = domain.getRange(); ValueAxis range = xyplot.getRangeAxis(); valueRange = range.getRange(); } } if (domainRange != null) { plot.getDomainAxis().setRange(domainRange); } if (valueRange != null) { Logger.getLogger(getClass().getName()).info("Setting previous value range!"); } handle.progress("Adding plot to panel", 5); final XYPlot targetPlot = plot; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { final FoldChangeViewPanel cmhp = cvtc.getLookup().lookup(FoldChangeViewPanel.class); cmhp.setPlot(targetPlot); cvtc.requestActive(); } }); } finally { handle.finish(); } }