anyway to figure out the max color of an image - fast?

hey,

I have two trace sops which basically are cooking all the time, even though they don’t need to. Most of the times, the image is black so the trace spends a lot of time tracing, but it doesn’t need to.

The only way I know of that can tell me whether or not the image is worth tracing is the trace sop itself (npoints()==0)

is there any other way? I have quite a few trace sops that are getting in the way. Also, I could bunch them together a bit.

For example from the single image, if the chroma finds something blue, then a flag is raised (the image is basically not empty). If it finds something yellow (the yellow chroma top is not empty) then another flag is raised. If I could raise those flags just by looking at one chroma image or another instead of having to trace both and then check the npoints of the trace [which btw seems to recook the trace op again, infact the one whose point I use in a switch statement takes double to cook than the other] to see which trace has points, either blue or yellow.

suggestions are welcome!
d

Ben made a motion sensor .tox a while ago located here.
[url]http://www.derivativeinc.com/forum/viewtopic.php?f=22&t=179[/url]

This tox file counts the number of pixels that have a luminance greater than some threshold. It can be edited for your purposes and is very fast (all done using GLSL TOPs).

The general idea is:

You’ll see a long chain of GLSL TOPs, each GLSL TOP is half the width and half the height of the previous TOP.
Each TOP does this: For each pixel of output on the current TOP, it samples 4 pixels from the input, and combines their values in some way.
This is done over and over again until the image is 1x1, at which point you can use a TOP to CHOP to get the result.
There are two shaders in this example, the first one is used on the first downsize and does the threshold check. It sets the pixel value to the number of pixels that are above the threshold. Every TOP after that is using a different shader that simply sums up the pixels of the previous TOP. The final TOP will have a 1x1 pixel that contains the number of pixels that were above the threshold. Now one catch is that the highest number Ben’s video card could hold for a pixel value was 65355 or so, so he had to scale the values by 1/2 each time, and then scale them back up at the end, you won’t need to do this for your case.

In your case you’d likely just need to edit the first shader and use it for every GLSL TOP. Instead of checking for a threshold, you’d look at the 4 pixel values and output whatever the max color is. Doing this for every GLSL TOP will result in the final 1x1 TOP containing the max color of the image. Also there is a performance hit on Bens sample because all of the TOPs are set to 32-bit float pixel format. This is unnecessary for you so if you turn them all down to 8-bit it’ll run even faster.

This works best of your image is square and a power of two. (Otherwise it requires a little more shader coding to make sure you sample very pixel)

Let me know if you want more explanations on this.

Take your image in a TOP, send to a TOP to CHOP, then to an Analyze CHOP set to Maximum.

The TOP to CHOP can be set to RGB only (no A), on the whole image, or just R if you are looking at luminance only. The Analyze CHOP will give you a maximum per row of pixels. Then you can Shuffle CHOP it to get all the max values in one channel, and apply another Analyze CHOP to get the maximum of the whole image.

You can tweak it with a Resolution TOP first to get a decent image size, which also helps eliminate noise in the image.

No only can you get the max value, you can get the X Y position of the peak.

That’s only 5-8 nodes, and pretty fast.

Would it be possible to illuminate this a bit more?
I would love to make a network which kicks out the xy pos of the max luma pixel.

Looking through the nodes you are talking about, I don’t quickly see a method to do what you are saying.

Thank you.

Asa(as chriskelly)