Cycles node editor - Map gray scale value map to extremes
The only solution and a major workaround that would work is:


Create a frame change handler that grabs bpy.data.textures and for each texture determines the min and max value in it (by iterating over all pixels). This would be slow. The data should be outputted to some scene custom prop array for example.
Drive a math cycles nodes with those custom prop array items. Everytime you switch texture you would need to re-target to appropriate array item (index). With this the rest of shader is simple.




With only nodes it's impossible because they operate per-sample. You would have to use as many nodes as are pixels in the texture and compare them (you can sample any pixel from texture with mapping vectors).

It would be possible if the min/max values could be encoded into the image (for example as grey values in 2 exact corners). The shader then would crop the texture by some extend and wouldn't use the border of the image with encoded data.



With OSL it's definitely doable but the texture would have to be part of that shader, it wouldn't work with RGB input socket (reason as above). Instead a path to the texture could be an input for such shader.