Brillo significa cambiar el valor de todos y cada uno de los píxeles de la imagen. Este cambio se puede realizar aumentando o disminuyendo los valores de píxel de la imagen, por cualquier constante. Este artículo brinda un conocimiento profundo sobre cómo se puede cambiar el brillo de una imagen usando OpenCV.
Input : Original Image Output : -> Original Image -> Image with brightness increased by 100 -> Image with brightness increased by 50 -> Image with brightness decreased by 100 -> Image with brightness decreased by 50
Código: código CPP para manipular el brillo de la imagen
// c++ code explaining how to // increase or decrease the brightness of // an image // loading library files #include <highlevelmonitorconfigurationapi.h> #include <opencv2\highgui\highgui.hpp> #include <opencv2\opencv.hpp> using namespace cv; using namespace std; int main(int argc, char** argv) { // Loading the Image File under testing Mat image = imread("C:\\Users\\dell\\Desktop\\abc.jpg"); // Check whether the image is present or not if (image.empty()) { cout << "Could not open or find the image" << endl; // waiting for any key to be pressed return -1; } // Declaring the Brightness Instances Mat imageBrighnessHigh50; // increasing the brightness level by 50 image.convertTo(imageBrighnessHigh50, -1, 1, 50); Mat imageBrighnessHigh100; // increasing the brightness level by 100 image.convertTo(imageBrighnessHigh100, -1, 1, 100); Mat imageBrighnessLow50; // decreasing the brightness level by 50 image.convertTo(imageBrighnessLow50, -1, 1, -50); Mat imageBrighnessLow100; // decreasing the brightness level by 100 image.convertTo(imageBrighnessLow100, -1, 1, -100); // Declaring the windows // for images belonging to different brightness level String windowNameOriginalImage = "Original Image"; String windowNameBrightnessHigh50 = "Brightness Increased by 50"; String windowNameWithBrightnessHigh100 = "Brightness Increased by 100"; String windowNameBrightnessLow50 = "Brightness Decreased by 50"; String windowNameBrightnessLow100 = "Brightness Decreased by 100"; // Running the window instance // and opening it namedWindow(windowNameOriginalImage, WINDOW_NORMAL); namedWindow(windowNameBrightnessHigh50, WINDOW_NORMAL); namedWindow(windowNameWithBrightnessHigh100, WINDOW_NORMAL); namedWindow(windowNameBrightnessLow50, WINDOW_NORMAL); namedWindow(windowNameBrightnessLow100, WINDOW_NORMAL); // Loading images inside the above created Windows imshow(windowNameOriginalImage, image); imshow(windowNameBrightnessHigh50, imageBrighnessHigh50); imshow(windowNameWithBrightnessHigh100, imageBrighnessHigh100); imshow(windowNameBrightnessLow50, imageBrighnessLow50); imshow(windowNameBrightnessLow100, imageBrighnessLow100); // waiting for any key to be pressed waitKey(0); // closing all the windows instances // when any key is pressed. destroyAllWindows(); return 0; }
Aporte :
Salida:
imagen original
Nivel de brillo aumentado en 50
Nivel de brillo aumentado en 100
Nivel de brillo disminuido en 50
Nivel de brillo disminuido en 100
Explicación :
// Declaring the Brightness Instances Mat imageBrighnessHigh50; // increasing the brightness level by 50 image.convertTo(imageBrighnessHigh50, -1, 1, 50); Mat imageBrighnessHigh100; // increasing the brightness level by 100 image.convertTo(imageBrighnessHigh100, -1, 1, 100); Mat imageBrighnessLow50; // decreasing the brightness level by 50 image.convertTo(imageBrighnessLow50, -1, 1, -50); Mat imageBrighnessLow100; // decreasing the brightness level by 100 image.convertTo(imageBrighnessLow100, -1, 1, -100);
Estas líneas de código cambiarán los valores de píxeles de la imagen en una cantidad específica. La imagen modificada final se almacena luego en la imagen de salida dada. El nivel de brillo aumentará si la cantidad especificada es positiva (como arriba es 50); de lo contrario, disminuirá si la cantidad especificada es negativa.
Función MAT:
La función «MAT» cambia el valor de cada píxel de la imagen al tipo de datos de destino y los valores se cambian según el aumento o la disminución.
Parameters : m : Output Image rtype : Output Image type, Output Image type is same as input if it is set to -ve value alpha : Input image pixel are multiplied with this number prior to its assignment to output image beta : adding this value to each input image pixel
Publicación traducida automáticamente
Artículo escrito por mathemagic y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA