ColdFusion Image Histogram
Example Output Histogram Image:
Example Source Image:
CFDump of color histogam and statistics:
This ColdFusion component creates black/white and color image histograms.
the component will return a structure containing histogram array(s) and statistics and/or will write PNG images of the histogram.
ColdFusion 8 Version:
Uses standard Java API currently available to ColdFusion 8, no need for external libraries (JAI now avaiable to CF8).
ColdFusion 8 Version now returns an image (in cfimage format) of a B/W or color histogram.
ColdFusion 7 Version:
Uses standard Java API currently available to ColdFusion, no need for external libraries.
New: JAI (Java Advanced Imaging) will be used if available in ColdFusion Class Path.
Using JAI provides a massive speed increase.
Download
-
CFImageHistogram (49Kbytes)
- June 30, 2007
imageHistogram Version 0.3.1 & CF8ImageHistogram 0.1
Features:
- Can be used to index colors of images so they can be searched
- Creates Black/White and color histograms
- Returns histogram statistics: min, max, mean, standard deviation
- Creates B/W and color histogram images
- Can create histogram from JPG file and path or from a buffered image
- Can use JAI (if available in ColdFusion Class Path) or if JAI not available will standard Java API currently available to ColdFusion 6/7
- Massive speed increase in version 0.3 when using JAI
- Apache License, version 2
Known Issues:
- Output PNG width currently set to 256 pixels
- VERY slow if JAI not used
- Histogram image output accuracy not well tested
- Using JAI is highly recommended
Feedback, bugs, feature request, better ideas are greatly appreciated.
ColdFusion 8 Histogram CFC Example Usage
- getHistogram - retuns a structure that contains a histogram array[256] and histogram statistics
- getColorHistogram - returns a structure that contains a color histogram array[3][256] and histogram statistics
- getHistogramImage - Returns an image histogram in cfimage format
- getColorHistogramImage - Returns a color image histogram in cfimage format
- setBufferedImage - allows you to define a buffered image to retrieve histogram from
Example use to get color histogram array from an image:
<cfset ih = createObject("component","imageHistogramCF8").init() />
<cfset image = expandPath("01.jpg") />
<cfset hist = ih.getColorHistogram(image) />
<cfdump var="#hist#">
Example of displaying a color histogram image:
<cfimage action="read" source="01.jpg" name="image" />
<cfset ih = createObject("component","imageHistogramCF8").init() />
<cfset hist = ih.getColorHistogramImage(image) />
<cfimage action="writeToBrowser" source="#hist#" />
ColdFusion 7 Histogram CFC Example Usage
- getHistogram - retuns a structure that contains a histogram array[256] and histogram statistics
- getHistogramImage - Creates an image (PNG) histogram
- getColorHistogram - retuns a structure that contains a color histogram array[3][256] and histogram statistics
- getColorHistogramImage - Creates an color image (PNG) histogram
- getHistogramValue - reutrn the value of the variables.histogram structure (will be empty unless one of the above functions is called first)
- setBufferedImage - allows you to define a buffered image to retrieve histogram from without having to specify a file path
- setImageBackgroundColor - sets the background color for the PNG images created red,green,blue,alpha
<cfscript>
//return histogram structure of supplied image
imageHistogram = createObject("component","imageHistogram").init();
histogram = imageHistogram.getHistogram(expandPath("test.jpg"));
//create histogram image
imageHistogram = createObject("component","imageHistogram").init();
imageHistogram.getHistogramImage(expandPath("test.jpg"),expandPath("hist.png"));
//return color histogram structure of supplied image
imageHistogram = createObject("component","imageHistogram").init();
histogram = imageHistogram.getColorHistogram(expandPath("test.jpg"));
//create color histogram image
imageHistogram = createObject("component","imageHistogram").init();
imageHistogram.getColorHistogramImage(expandPath("test.jpg"),expandPath("hist.png"));
//set white background PNG histogram image color
imageHistogram = createObject("component","imageHistogram").init();
imageHistogram.setImageBackgroundColor(255,255,255,255);
//get histogram from already buffered image, variable 'bufferedImage'
imageHistogram = createObject("component","imageHistogram").init();
imageHistogram.setBufferedImage(bufferedImage);
histogram = imageHistogram.getHistogram();
</cfscript>