1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

Small Coreimage Histogram problem

Posted by Mark M on Apr 28, 2007

Hello,

I'm trying to use coreimage to investigate some image properties and I'm having a little trouble figuring out the histogram function. I'm not sure if the way it's implemented is a mistake or if I'm just not seeing its value

For instance if I make a simple gradient and then look at the numbers produced by the histogram they don't really add up:

size(800, 1600)
coreimage = ximport("coreimage")
canvas = coreimage.canvas(1, 256)
 
# make gradient to get a fairly even distribution of values
l = canvas.layer_linear_gradient()
# get the pixels
p = l.pixels()
hist = p.histogram()
#histogram values from red channel
print hist[0]
The doc string in the code suggests that this should be returning percentages of each value, but this is not happening. The issues is in line 2406
n = n / n[Numeric.argmax(n)]
dividing by the max value doesn't seem so useful. Should this be:
n = n / len(p)
in order to give a real percentage of the number of occurrences of each value? Or am I missing something?
Thanks


 
Posted by Mark M on Apr 28, 2007

I think I just figured out what is going on. Dividing by the max count gives a different normalization of the histogram, which seems to be just as useful from a statistical point of view, but was causeing me problems since it wasn't obvious how to get the raw pixel numbers.



Posted by Tom De Smedt on Apr 30, 2007

Hi Mark,

At the time I wrote the histogram function I made it so that it would visually produce the same output as a histogram from Photoshop. Now that I look at the numbers again, the output is indeed difficult to interpret. There are some other issues as well (e.g. indices for a channel seem to go only up to 253) so I'm going to have to review this code.

Thanks for pointing it out.