วิธีการลดความสว่างจะคล้ายกันมากกับการเพิ่มความสว่าง ข้อแตกต่างเพียงอย่างเดียวคือการลบ 'สเกลาร์ (B, G, R)' ออกจากรูปภาพ เรากำลังลบค่าสเกลาร์เพื่อลดความสว่าง
โปรแกรมต่อไปนี้แสดงวิธีลดความสว่างของรูปภาพใน OpenCV
ตัวอย่าง
#include<iostream>
#include<opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main() {
Mat original; //Declaring a matrix to load the original image//
Mat dimmer;//Declaring a matrix to load the image after changing the brightness//
namedWindow("Original");//Declaring window to show the original image//
namedWindow("Dimmer");//Declaring window to show the brighter image//
original = imread("bright.jpg");
dimmer = original - Scalar(80, 80, 80);//subtracting integer value to change the brightness//
imshow("Original", original);//showing original image//
imshow("Dimmer", dimmer);//showing brighter image//
waitKey(0);//wait for keystroke//
return(0);
} ผลลัพธ์
