detecting the brightest pixels

frankenkat's picture

Hi, I'm trying to develop a composition that takes in an image. Scans through it and places a graphic on the brightest pixels of the image (sort of like a sparkle filter). From scanning through the forums it seems like there are a number of ways to accomplish this and I'm trying to figure out the best way. Is it Javascript, Core image Kernel, or a combination of both?

cwright's picture
Re: detecting the brightest pixels

JS won't help you any (it has no support for images), CI might be a good start, but it's still difficult to work with. If you're on 10.6, you could use CL, which would be able to handle a problem like this nicely.

Lango's picture
Re: detecting the brightest pixels

Hi frankenkat

Do you need a brightest pixel or the brightest area?

What exactly do you mean by brightest? Most white? Will there be other colours?

I have a custom patch that I have made which can break an image into a grid and each cell in the grid has a weight depending on how much brightness is in the section of the image that corresponds to the area and position of that cell.

You could then loop through this grid with javascript and easily get the details of the brightest cell, giving you the x and y position in units.

In theory you could change the size of each cell to be the size of a pixel, but i don't believe it will perform that well.

Let me know if you think this would work.

Regards

Lango

frankenkat's picture
Re: detecting the brightest pixels

I think that would work. I'm looking to get the most white cell. I ran into your patch in another forum but I was unable to get it working. What you've got there is essentially what I want to do (I'd like to eventually swap out the squares for other graphics) could you post your patch or send it to me? thanks frank

toneburst's picture
Re: detecting the brightest pixels

OpenCL should be ideal for this kind of thing. Unfortunately, I'm not sure it's possible to output a single vec2 (for the XY coords of the brightest pixel) from an OpenCL Kernel patch. I'm still a bit confused about how to get data in and out of an OpenCL patch, I must admit, since there doesn't seem to be an explicit way of declaring in and out variables in OpenCL, as there is with the JavaScript patch, for example. I don't see why Apple couldn't have added some kind of extra keywords for specifying which variables should create input ports and which output ports. I know this isn't in the OpenCL spec, but it would make things a lot simpler.

a|x