Compositor: Get the second darkest value I have an image that is mostly values between .3 and 1, but has a few areas of solid black. I want to set all the pure black areas (or perhaps near black to also catch aliased edges) to be the next lowest value instead.

This is possible with color ramps on a per image basis, but I need a setup that will work across multiple frames where the specific values could change quite a lot (in one frame it may be .3, then the next .5, etc.)

It seems like the way to accomplish this would be to create a mask of the dark areas, and then have a node group that mixes that area with the second lowest value. For this to work, I need some way to get the lowest value in an image, and a way to ignore certain areas.

Is this possible? Or any other ways to solve this issue?
This node setup is mostly what HenrikD proposed:



It takes an image input and tests for pixels whose R, G, and B values are all less than a user-specified value (in this screenshot, it was .0005, which appears as .001 in the entry box).  Those pixels can then be replaced by any user-specified color, I'm using red here to show the affected pixels but you would instead substitute your almost-black color.

Output with limit value of .01:



Output with limit value of .03:



If it is necessary to actually calculate the almost-black color from the image itself . . . I'm not offhand sure how to do that, sorry.