Changing the brightness means changing the value of pixels. It means adding or subtracting value some integer value with the current value of each pixel. When you add some integer value with every pixel, it means you are making the image brighter. When you subtract some constant value from all of the pixels, you are reducing the brightness. First, we will learn how to increase the brightness and second we will learn how to reduce the brightness.Increasing the BrightnessIncreasing the Brightness using OpenCV is very easy. To increase the brightness, add some additional values with each channel, and the brightness ... Read More
OpenCV has C++ STL compatible 'Mat iterator' class. Using this 'Mat iterator' class, we can access pixels very easily. We have to create an object of 'Mat iterator' class. We can do it as 'Mat_: : iterator example'. We have to use an underscore after 'Mat' like 'Mat_' because it is a template method. In this method, the return type must be specified while creating an object of 'iterator' class. That is why we have declared the datatype .The following program demonstrates how to reduce the color using Iterator Method in OpenCV.Example#include #include using namespace std;//Declaring std namespace using namespace ... Read More
In image processing, we perform computation on the image. To be more specific, we perform a calculation on pixel so the higher the number of pixels, the more the time consuming the computation becomes. To reduce the computation time, we require to scan the image efficiently. We will learn how to implement an efficient image scanning loop using pointers.Here we will see the pixel scanning process with an example of the color reduction strategy. Color images such as RGB images are composed of 3 channels. Each of these channels has the same number of pixels but with corresponding values. Each ... Read More
To read the value of a specific pixel, we can use either 'at' or 'direct access' method. Here, we will learn both of the approaches.Let's start with 'at' method. The following program reads the pixel value located at (10, 29) of an RGB image.Example#include #include using namespace std; using namespace cv; int main() { Mat image;//taking an image matrix// image = imread("sky.jpg");//loading an image// int x = image.at(10, 29)[0];//getting the pixel values// int y = image.at(10, 29)[1];//getting the pixel values// int z = image.at(10, 29)[2];//getting the pixel values// cout
In the previous method (the 'at' method), we need to specify the image type while accessing the pixel values. There is another method which is simpler than 'at' method. It is called direct access method. To access pixel value using this method, we need to specify the Mat type such as Mat, Mat, Mat and so on.The following program demonstrates how to change Pixel Values using Direct Access Method in OpenCV.Example#include #include using namespace cv;//Declaring cv namespace using namespace std; void direct_access(Mat_ &image, int n){ //Declaring the function// for (int x = 0; x < n; x++){ //initiating a ... Read More
In a grayscale image, the pixel value is a single numeric value. But in a color image such as RGB image, the pixel is a vector having three values. These three values represent three channels.Here we will create a function that accesses both the grayscale image and RGB image pixel values and randomly adds noise to image pixels. Then we call the function inside the main() function to observe the result.The following program demonstrates how to change Pixel Values using 'at' method in OpenCV.Example#include #include using namespace cv;//Declaring cv namespace using namespace std; void adding_Noise(Mat& image, int n){ //'adding_Noise' function// ... Read More
To draw an ellipse, we need a center, major axis and minor axis. That means we need three parameters for the ellipse. We need a matrix where we will draw the ellipse, and we need to declare line thickness and line color.When we want to draw an ellipse using OpenCV, we have to mention the angle of rotation, and there are two additional parameter starting point and ending point. To call 'ellipse()' function, we need to include header file.The basic syntax of this method is as follows −Syntaxellipse(whiteMatrix, center, xy, angle, starting_point, ending_point, line_Color, thickness);The following program shows how to ... Read More
Here, we will understand how to save the OpenCV image to any location on your computer. OpenCV provides imwrite() function to save an image to a specified file. The file extension represents the image format. The actual format of the function is −imwrite("Destination/Name of the image with extension", Source Matrix)Here, "Destination" is where we want to save the image. In this program, we save the image as "Lakshmi.jpg". We can give any name to the image. The "Source Matrix" is the matrix where the image has been loaded. In this program, the image is loaded as "myImage" matrix.Example#include #include using namespace ... Read More
A binary image is just a digital image that represents two colors, black and white. From an image processing perspective, a binary image contains pixels with two possible values- zero and one. When the value of a pixel is 0, it represents a pure black color. When the value of the pixel is 1, it means pure white color.In a grayscale image, there are 256 different possible values for each. But in Binary Image, there are only two possible values. Binary images have different types of applications. For example, morphological transformation requires a binary image, object shape extraction from background ... Read More
Inverting a binary image means inverting the pixel values. From a visual perspective, when we invert a binary image, white pixels will be converted to black, and black pixels will be converted to white.The basic form of this function is −cvtColor(original_image, grayscale_image, COLOR_BGR2GRAY);The next line is converting the grayscale image into a binary image and storing the converted image into 'binary_image' matrix.threshold(grayscale_image, binary_image, 100, 255, THRESH_BINARY);Here 'grayscale_image' is the source matrix, 'binary_image' is the destination matrix. After that, there are two values 100 and 255. These two values represent the threshold range. In this line, the threshold range represents the ... Read More