public static boolean isWhite(PGraphics g, int incomingPix, float brightnessTresh) { return g.brightness(incomingPix) > brightnessTresh; }
public final float brightness(int what) { return g.brightness(what); }
/** * ( begin auto-generated from brightness.xml ) * * Extracts the brightness value from a color. * * ( end auto-generated ) * * @webref color:creating_reading * @usage web_application * @param rgb any value of the color datatype * @see PGraphics#red(int) * @see PGraphics#green(int) * @see PGraphics#blue(int) * @see PGraphics#alpha(int) * @see PGraphics#hue(int) * @see PGraphics#saturation(int) */ public final float brightness(int rgb) { return g.brightness(rgb); }
public static boolean colorFinderHSBRedish(PGraphics g, int baseline, int incomingPix, float hueTresh, float saturationTresh, float brightnessTresh) { float h1 = g.hue(baseline); float h2 = g.hue(incomingPix); // If the hue is low but still red, shit it. if (h2 < 30) { h2 = h2 + 255f; } return abs(h1 - h2) < hueTresh && // Avoid desaturated pixels abs(g.saturation(incomingPix) - g.saturation(baseline)) < saturationTresh && // avoid pixels not bright enough abs(g.brightness(incomingPix) - g.brightness(baseline)) < brightnessTresh; }
/** * Color distance on the HSB scale. The incomingPix is compared with the * baseline. The method returns true if each channel validates the condition * for the given threshold. * * @param g * @return */ public boolean colorFinderHSB(PGraphics g, int incomingPix) { float h1 = g.hue(referenceColor); float h2 = g.hue(incomingPix); return abs(h1 - h2) < hue && // Avoid desaturated pixels abs(g.saturation(incomingPix) - g.saturation(referenceColor)) < saturation && // avoid pixels not bright enough abs(g.brightness(incomingPix) - g.brightness(referenceColor)) < brightness; }
/** * Warning here, the threshold is the same for each channel. Often the range * depends on the declaration. To change the intensity of each, try to call * HSB(100, 100, 100) for even thresholding or HSB(100, 200, 50) to be less * picky on the brigthness and more picky on the saturation. * * @param g * @param baseline * @param incomingPix * @param threshold * @return */ public static boolean colorDistHSBAutoThresh(PGraphics g, int baseline, int incomingPix, float threshold) { float h1 = g.hue(baseline); float h2 = g.hue(incomingPix); float d1 = abs(h1 - h2); float d2 = abs(g.saturation(baseline) - g.saturation(incomingPix)); float d3 = abs(g.brightness(baseline) - g.brightness(incomingPix)); return (d1 + d2 + d3) < (threshold * 3); }
/** * Color distance on the HSB scale. The incomingPix is compared with the * baseline. The method returns true if each channel validates the condition * for the given threshold. * * @param g * @param baseline * @param incomingPix * @param hueTresh * @param saturationTresh * @param brightnessTresh * @return */ public static boolean colorDistHSB(PGraphics g, int baseline, int incomingPix, float hueTresh, float saturationTresh, float brightnessTresh) { float h1 = g.hue(baseline); float h2 = g.hue(incomingPix); return abs(h1 - h2) < hueTresh && // Avoid desaturated pixels abs(g.saturation(incomingPix) - g.saturation(baseline)) > saturationTresh && // avoid pixels not bright enough abs(g.brightness(incomingPix) - g.brightness(baseline)) > brightnessTresh; }
/** * Color distance on the HSB scale. The incomingPix is compared with the * baseline. The method returns true if each channel validates the condition * for the given threshold. * * @param g * @param baseline * @param incomingPix * @param hueTresh * @param saturationTresh * @param brightnessTresh * @return */ public static boolean colorFinderHSB(PGraphics g, int baseline, int incomingPix, float hueTresh, float saturationTresh, float brightnessTresh) { float h1 = g.hue(baseline); float h2 = g.hue(incomingPix); return abs(h1 - h2) < hueTresh && // Avoid desaturated pixels g.saturation(incomingPix) > 180 && // Good saturation abs(g.saturation(incomingPix) - g.saturation(baseline)) < saturationTresh && // avoid pixels not bright enough abs(g.brightness(incomingPix) - g.brightness(baseline)) < brightnessTresh; }