Compositor: Get the second darkest value
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.