How to change the dynamical range?

Hello,

I’m doing a project using qt and OpenCV.

As input images, i can have any type but the most common will be grayscale 16 bits (CV_16U).

I’m plotting the histogram and i added two cursor to let the user choose the dynamical range.

in detail, the image have pixel of value from 0 to 65535 (or (0…255, 0…255, 0…255) or (0…65535, 0…65535, 0…65535) or other type i think you understood the idea) if the user want to rescale the dynamical range between 1000 to 2000 he can use the cursor

Before to used opencv i managed it by my own. The image was store in a ushort array with a simple for loop on each pixels. that worked well and i was also able to add more scaling type (not only linear scaling).

But, in way to, simplify my code, to generalyse it to different type of images and to improve speed of execution i decided to use OpenCV. The problem is, I don’t know how to do that with opencv.

I already tried with convertTo and with normalized but it was not really conclusive.

I know that i could use my previous technic with a for loop replacing the iteration along the array by mymat.at(i) but i want something more light than a for loop and i can’t imagine that they are not this kind of function in OpenCV.

How can i do that (if possible in general way to manage different image type)?

Thank you in advance