Skip to main content
Participant
December 22, 2014
Question

How can I get high and low value of a histogram?

  • December 22, 2014
  • 1 reply
  • 804 views

Is it possible the get the luminance value of brightest pixel and darkest pixel in an image using aescript?

This topic has been closed for replies.

1 reply

UQg
Legend
December 23, 2014

The simplest way would be to add a level effect, and read the histogram from there, but unfortunately histograms have a propertyValueType that scripts can't read.

Probably the only way is to add an expression control with a sampleImage expression, make a big loop over all pixels, and collect the successive expression values.

I just made a quick test by curiosity, it took 212 seconds (3min30) for a 1024x768 image to collect the luminance histogram at comp.time... probably not viable for you.

Xavier.

Participant
December 23, 2014

I was wondering about a technique like that. But since I'm not looking for absolute accuracy, How about adding the mosaic effect with sharp colors selected.  Then you can then skip pixels and just sample the 100 squares. I have no idea how to script that, but it should work.

UQg
Legend
December 27, 2014

Actually you don't need a mozaic effect, the sampleImage expression can specify a (sampling) radius.

The method would be to

1- add a slider control to the layer,

2- in a loop over x and over y (the coordinates of the center of the sampling point),

         - set the slider control expression to

rgbToHsl(sampleImage([x,y], radius, postEffect, time))[2];

    

          (this first evaluates the [R,G,B,Alpha] color of the layer in a rectangle of half size [radius[0], radius[1]] centered at [x,y], at the time specified, pre or post effect depending on postEffect (true/false),

          then converts it to [H,S,L, Alpha], picks the "L" entry (a number in [0,1]);

        

          - harvest the result of the expression,

          - compare to previous values: if below min or above max, store new min or max, and coordinates.

3- when it's done, remove the slider control.

For the previous post i had used radius = [0.5, 0.5] so you get pixel accuracy (as in your original post).

But increasing the radius can speed things up greatly.

Dividing a 1024x768 image into C columns (and roughly C*layer.height/layer.width rows), i got these times:

C = 100 (num samples: 7500) time 1.7 sec

C = 50 (num samples: 1900) time 0.45 sec

C = 25 (num samples: 475) time: 0.13 sec

I think it is slow because the sampleImage expression itself  is a little bit slow, but maybe also because of all the history entries (undos) such a script creates.

Putting everything in an undoGroup speed things up a bit, but not much.

Xavier.