Wednesday, May 11, 2011

BitmapData: histogram

public function histogram(hRect:Rectangle = null):Vector.<Vector.<Number>>

Computes a 256-value binary number histogram of a BitmapData object. This method returns a Vector object containing four Vector. instances (four Vector objects that contain Number objects). The four Vector instances represent the red, green, blue and alpha components in order. Each Vector instance contains 256 values that represent the population count of an individual component value, from 0 to 255.

var hist:Vector.<Vector.<Number>> = bmpData.histogram();
// RGBA order
hist[0][9] = number of pixels having the red color component 9. eg.: 0x093366
total of hist[0][0-255] = total number of pixels in hRect region of bmpData.

flash + webcam + color tracking

Created pixel bender shaders to convert RGB to HSV
Used probability densities to back project histogram
using camshift algorithm

http://psalmhundred.net/experiment/webcam/webcam_demo_color_detect.html