How can I change brightness&contrast of image

Hi everyone. I have an 8UC1 image and I want to change its brightness and contrast. I have gui for it and there is 2 sliders in gui:

cv::Mat img = ... ;

sliderBrightness(int value){
cv::Mat imgB = img + cv::Scalar(value * 255/100.0); //I am currently changing brightness like this but not sure if its correct way.
...
}
sliderContrast(int value){}

Here value is in 0-99 range according to slider’s position. Which functions should i use for these operations?

you’re putting the cart before the horse …

and no, we wont write your program,
instead, please study tutorials, before asking :

https://docs.opencv.org/4.x/d7/da8/tutorial_table_of_content_imgproc.html

I didn’t ask to you anywhere to write my program. I just asked for what should i do for changing these two things. And you are pointing wrong link. Right doc : OpenCV: Changing the contrast and brightness of an image!
I did this and still have a question but this website looks kinda dead and you seem like you don’t know more than me so i am passing my questions.

if you choose to go with OpenCV’s “highgui”, you will need:

  • a “display” function that gets the positions of both trackbars, prepares what you want to show, and calls imshow() to present this
  • namedWindow()
  • two trackbars in that window
  • installation of callbacks for both trackbars, which call the display() function
  • an initial call to display() before the main loop to present something
  • a main loop running waitKey()

please research what “brightness” and “contrast” mean in terms of implementation (numerically). less brutal operations are gain and gamma adjustment. RGB space isn’t linear.

careful ! this will only initialize the 1st (b) component of the Scalar (the g,r ones will be zero !) for 3 channel images, you need all 3, like:

ìmg + Scalar(x,y,z);