I am playing with images changing their contrast but I don't know how to restore the contrast back of an image after modifying it first.
I understand with a value greater than 1 I increase the contrast and with a value between 0 and 1 I decrease it.
I tried with OpenCV
and with a ColorMatrix
in Android
.
For example, using OpenCV
, first I double the contrast of an image like this:
src.convertTo(dst, -1, 2, 0);
and then I decrease it by half:
src.convertTo(dst, -1, 0.5, 0);
but after decreasing it the resulting image is not the same as the original one I had before doubling the contrast.
With Android
, I was using this colorMatrix to double the contrast:
ColorMatrix cm = new ColorMatrix();
cm.set(new float[] {
2, 0, 0, 0, 0,
0, 2, 0, 0, 0,
0, 0, 2, 0, 0,
0, 0, 0, 1, 0});
and this to decrease it by half:
ColorMatrix cm = new ColorMatrix();
cm.set(new float[] {
0.5, 0, 0, 0, 0,
0, 0.5, 0, 0, 0,
0, 0, 0.5, 0, 0,
0, 0, 0, 1, 0});
I tried with different values and research on the Internet but I can't figure out the equivalences between increasing and decreasing contrast.
Does anybody know how to do this?