当前位置: 首页>>代码示例>>Java>>正文


Java ColorHsv类代码示例

本文整理汇总了Java中boofcv.alg.color.ColorHsv的典型用法代码示例。如果您正苦于以下问题:Java ColorHsv类的具体用法?Java ColorHsv怎么用?Java ColorHsv使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ColorHsv类属于boofcv.alg.color包,在下文中一共展示了ColorHsv类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: coupledHueSat

import boofcv.alg.color.ColorHsv; //导入依赖的package包/类
/**
 * HSV stores color information in Hue and Saturation while intensity is in Value.  This computes a 2D histogram
 * from hue and saturation only, which makes it lighting independent.
 */
public static double[] coupledHueSat(BufferedImage image) {
    Planar<GrayF32> rgb = new Planar<>(GrayF32.class, image.getWidth(), image.getHeight(), 3);
    Planar<GrayF32> hsv = new Planar<>(GrayF32.class, image.getWidth(), image.getHeight(), 3);

    ConvertBufferedImage.convertFrom(image, rgb, true);
    ColorHsv.rgbToHsv_F32(rgb, hsv);

    Planar<GrayF32> hs = hsv.partialSpectrum(0, 1);

    // The number of bins is an important parameter.  Try adjusting it
    Histogram_F64 histogram = new Histogram_F64(10, 10);
    histogram.setRange(0, 0, 2.0 * Math.PI); // range of hue is from 0 to 2PI
    histogram.setRange(1, 0, 1.0);         // range of saturation is from 0 to 1

    // Compute the histogram
    GHistogramFeatureOps.histogram(hs, histogram);
    histogram.value[0] = 0.0; // remove black

    UtilFeature.normalizeL2(histogram); // normalize so that image size doesn't matter

    return histogram.value;
}
 
开发者ID:tomwhite,项目名称:set-game,代码行数:27,代码来源:ImageUtils.java

示例2: printClickedColor

import boofcv.alg.color.ColorHsv; //导入依赖的package包/类
/**
 * Shows a color image and allows the user to select a pixel, convert it to HSV, print
 * the HSV values, and calls the function below to display similar pixels.
 */
public static void printClickedColor( final BufferedImage image ) {
	ImagePanel gui = new ImagePanel(image);
	gui.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent e) {
			float[] color = new float[3];
			int rgb = image.getRGB(e.getX(),e.getY());
			ColorHsv.rgbToHsv((rgb >> 16) & 0xFF,(rgb >> 8) & 0xFF , rgb&0xFF,color);
			System.out.println("h = " + color[0]);
			System.out.println("s = "+color[1]);
			System.out.println("v = "+color[2]);

			showSelectedColor("Selected",image,(float)color[0],(float)color[1]);
		}
	});

	ShowImages.showWindow(gui,"Color Selector");
}
 
开发者ID:intrack,项目名称:BoofCV-master,代码行数:23,代码来源:ExampleSegmentColor.java

示例3: independentHueSat

import boofcv.alg.color.ColorHsv; //导入依赖的package包/类
/**
 * Computes two independent 1D histograms from hue and saturation.  Less affects by sparsity, but can produce
 * worse results since the basic assumption that hue and saturation are decoupled is most of the time false.
 */
public static double[] independentHueSat(BufferedImage image) {
    // The number of bins is an important parameter.  Try adjusting it
    TupleDesc_F64 histogramHue = new TupleDesc_F64(5);
    TupleDesc_F64 histogramValue = new TupleDesc_F64(5);

    List<TupleDesc_F64> histogramList = new ArrayList<>();
    histogramList.add(histogramHue); histogramList.add(histogramValue);

    Planar<GrayF32> rgb = new Planar<>(GrayF32.class,1,1,3);
    Planar<GrayF32> hsv = new Planar<>(GrayF32.class,1,1,3);

    rgb.reshape(image.getWidth(), image.getHeight());
    hsv.reshape(image.getWidth(), image.getHeight());
    ConvertBufferedImage.convertFrom(image, rgb, true);
    ColorHsv.rgbToHsv_F32(rgb, hsv);

    GHistogramFeatureOps.histogram(hsv.getBand(0), 0, 2*Math.PI,histogramHue);
    GHistogramFeatureOps.histogram(hsv.getBand(1), 0, 1, histogramValue);

    // need to combine them into a single descriptor for processing later on
    TupleDesc_F64 imageHist = UtilFeature.combine(histogramList,null);

    UtilFeature.normalizeL2(imageHist); // normalize so that image size doesn't matter

    return imageHist.value;
}
 
开发者ID:tomwhite,项目名称:set-game,代码行数:31,代码来源:ImageUtils.java

示例4: filterBackgroundOut

import boofcv.alg.color.ColorHsv; //导入依赖的package包/类
public static BufferedImage filterBackgroundOut(BufferedImage image) {

        Planar<GrayF32> input = ConvertBufferedImage.convertFromMulti(image, null, true, GrayF32.class);
        Planar<GrayF32> hsv = new Planar<>(GrayF32.class, input.getWidth(), input.getHeight(), 3);

        // Convert into HSV
        ColorHsv.rgbToHsv_F32(input, hsv);

        // Euclidean distance squared threshold for deciding which pixels are members of the selected set
        float maxDist2 = 0.4f * 0.4f;

        // Extract hue and saturation bands which are independent of intensity
        GrayF32 H = hsv.getBand(0);
        GrayF32 S = hsv.getBand(1);

        float hue = H.get(1, 1);
        float saturation = S.get(1, 1);

        // Adjust the relative importance of Hue and Saturation.
        // Hue has a range of 0 to 2*PI and Saturation from 0 to 1.
        float adjustUnits = (float) (Math.PI / 2.0);

        // step through each pixel and mark how close it is to the selected color
        BufferedImage output = new BufferedImage(input.width, input.height, BufferedImage.TYPE_INT_RGB);
        for (int y = 0; y < hsv.height; y++) {
            for (int x = 0; x < hsv.width; x++) {
                // Hue is an angle in radians, so simple subtraction doesn't work
                float dh = UtilAngle.dist(H.unsafe_get(x, y), hue);
                float ds = (S.unsafe_get(x, y) - saturation) * adjustUnits;

                // this distance measure is a bit naive, but good enough for to demonstrate the concept
                float dist2 = dh * dh + ds * ds;
                if (dist2 > maxDist2 * 4) {
                    output.setRGB(x, y, image.getRGB(x, y));
                }
            }
        }
        return output;
    }
 
开发者ID:tomwhite,项目名称:set-game,代码行数:40,代码来源:ImageUtils.java

示例5: coupledHueSat

import boofcv.alg.color.ColorHsv; //导入依赖的package包/类
/**
 * HSV stores color information in Hue and Saturation while intensity is in Value.  This computes a 2D histogram
 * from hue and saturation only, which makes it lighting independent.
 */
public double[] coupledHueSat(byte[] image) throws IOException {
	Planar<GrayF32> rgb = new Planar<GrayF32>(GrayF32.class,1,1,3);
	Planar<GrayF32> hsv = new Planar<GrayF32>(GrayF32.class,1,1,3);

	BufferedImage buffered = ImageIO.read(new ByteArrayInputStream(image));
	if (buffered == null) {
		throw new RuntimeException("Can't load image!");
	}

	rgb.reshape(buffered.getWidth(), buffered.getHeight());
	hsv.reshape(buffered.getWidth(), buffered.getHeight());

	ConvertBufferedImage.convertFrom(buffered, rgb, true);
	ColorHsv.rgbToHsv_F32(rgb, hsv);

	Planar<GrayF32> hs = hsv.partialSpectrum(0,1);

	// The number of bins is an important parameter.  Try adjusting it
	Histogram_F64 histogram = new Histogram_F64(12,12);
	histogram.setRange(0, 0, 2.0 * Math.PI); // range of hue is from 0 to 2PI
	histogram.setRange(1, 0, 1.0);         // range of saturation is from 0 to 1

	// Compute the histogram
	GHistogramFeatureOps.histogram(hs,histogram);

	UtilFeature.normalizeL2(histogram); // normalize so that image size doesn't matter

	return histogram.value;
}
 
开发者ID:BotLibre,项目名称:BotLibre,代码行数:34,代码来源:Vision.java

示例6: showSelectedColor

import boofcv.alg.color.ColorHsv; //导入依赖的package包/类
/**
 * Selectively displays only pixels which have a similar hue and saturation values to what is provided.
 * This is intended to be a simple example of color based segmentation.  Color based segmentation can be done
 * in RGB color, but is more problematic.  More robust techniques can use Gaussian
 * models.
 */
public static void showSelectedColor( String name , BufferedImage image , float hue , float saturation ) {
	MultiSpectral<ImageFloat32> input = ConvertBufferedImage.convertFromMulti(image,null,ImageFloat32.class);
	MultiSpectral<ImageFloat32> hsv = new MultiSpectral<ImageFloat32>(ImageFloat32.class,input.width,input.height,3);

	// Ensure the the bands are in RGB order
	ConvertBufferedImage.orderBandsIntoRGB(input,image);

	// Convert into HSV
	ColorHsv.rgbToHsv_F32(input,hsv);

	// Pixels which are more than this different from the selected color are set to black
	float maxDist2 = 0.4f*0.4f;

	// Extract hue and saturation bands which are independent of intensity
	ImageFloat32 H = hsv.getBand(0);
	ImageFloat32 S = hsv.getBand(1);

	// Adjust the relative importance of Hue and Saturation
	float adjustUnits = (float)(Math.PI/2.0);

	// step through each pixel and mark how close it is to the selected color
	BufferedImage output = new BufferedImage(input.width,input.height,BufferedImage.TYPE_INT_RGB);
	for( int y = 0; y < hsv.height; y++ ) {
		for( int x = 0; x < hsv.width; x++ ) {
			// remember Hue is an angle in radians, so simple subtraction doesn't work
			float dh = UtilAngle.dist(H.unsafe_get(x,y),hue);
			float ds = (S.unsafe_get(x,y)-saturation)*adjustUnits;

			// this distance measure is a bit naive, but good enough for this demonstration
			float dist2 = dh*dh + ds*ds;
			if( dist2 <= maxDist2 ) {
				output.setRGB(x,y,image.getRGB(x,y));
			}
		}
	}

	ShowImages.showWindow(output,"Showing "+name);
}
 
开发者ID:intrack,项目名称:BoofCV-master,代码行数:45,代码来源:ExampleSegmentColor.java

示例7: main

import boofcv.alg.color.ColorHsv; //导入依赖的package包/类
public static void main( String args[] ) {
	BufferedImage image = UtilImageIO.loadImage("../data/applet/sunflowers.jpg");

	// Convert input image into a BoofCV RGB image
	MultiSpectral<ImageFloat32> rgb = ConvertBufferedImage.convertFromMulti(image, null, ImageFloat32.class);
	ConvertBufferedImage.orderBandsIntoRGB(rgb,image);

	//---- convert RGB image into different color formats
	MultiSpectral<ImageFloat32> hsv = new MultiSpectral<ImageFloat32>(ImageFloat32.class,rgb.width,rgb.height,3);
	ColorHsv.rgbToHsv_F32(rgb, hsv);

	MultiSpectral<ImageFloat32> yuv = new MultiSpectral<ImageFloat32>(ImageFloat32.class,rgb.width,rgb.height,3);
	ColorYuv.yuvToRgb_F32(rgb, yuv);

	//---- Convert individual pixels into different formats
	float[] pixelHsv = new float[3];
	ColorHsv.rgbToHsv(10,50.6f,120,pixelHsv);
	System.out.printf("Found RGB->HSV = %5.2f %5.3f %5.1f\n",pixelHsv[0],pixelHsv[1],pixelHsv[2]);

	float[] pixelRgb = new float[3];
	ColorHsv.hsvToRgb(pixelHsv[0],pixelHsv[1],pixelHsv[2],pixelRgb);
	System.out.printf("Found HSV->RGB = %5.1f %5.1f %5.1f expected 10 50.6 120\n",
			pixelRgb[0],pixelRgb[1],pixelRgb[2]);

	float[] pixelYuv = new float[3];
	ColorYuv.rgbToYuv(10,50.6f,120,pixelYuv);
	System.out.printf("Found RGB->YUV = %5.1f %5.1f %5.1f\n",pixelYuv[0],pixelYuv[1],pixelYuv[2]);

	ColorYuv.yuvToRgb(pixelYuv[0],pixelYuv[1],pixelYuv[2],pixelRgb);
	System.out.printf("Found YUV->RGB = %5.1f %5.1f %5.1f expected 10 50.6 120\n",
			pixelRgb[0],pixelRgb[1],pixelRgb[2]);
}
 
开发者ID:intrack,项目名称:BoofCV-master,代码行数:33,代码来源:ExampleColorSpace.java


注:本文中的boofcv.alg.color.ColorHsv类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。