
The point at (0, 0) corresponds to the top-left pixel in our image, whereas the point (7, 7) corresponds to the bottom-right corner. We see that we have an 8 x 8 grid with 64 total pixels. Here, we have the letter “I” on a piece of graph paper. OpenCV images are zero-indexed, where the x-values go left-to-right (column number) and y-values go top-to-bottom (row number). The origin, (0, 0), is located at the top-left of the image. Let’s look at the image in Figure 5 to make this point more clear: Figure 5: In OpenCV, pixels are accessed by their (x, y)-coordinates. As we move down and to the right, both the x and y-values increase. Using this graph paper, the point (0, 0) corresponds to the top-left corner of the image (i.e., the origin). Imagine our grid as a piece of graph paper. Overview of the image coordinate system in OpenCVĪs I mentioned in Figure 1, an image is represented as a grid of pixels. Now that we have a good understanding of pixels let’s have a quick review of the coordinate system. Similarly, to form the color red in the bottom-left, we simply fill the Red bucket completely, leaving the other Green and Blue buckets totally empty.įinally, blue is formed by filling only the Blue bucket, as demonstrated in the bottom-right.įor your reference, here are some common colors represented as RGB tuples: In the top-left example, we have the color white - each of the Red, Green, and Blue buckets have been completely filled to form the white color.Īnd on the top-right, we have the color black - the Red, Green, and Blue buckets are now totally empty. Look at the following image to make this concept more clear: Figure 4: Here, we have four examples of colors and the “bucket” amounts for each of the Red, Green, and Blue components, respectively. To create a pure red color, we would completely fill the red bucket (and only the red bucket): (255, 0, 0). Then, to create a black color, we would completely empty each of the buckets: (0, 0, 0) - since black is the absence of color. To construct a white color, we would completely fill each of the red, green, and blue buckets, like this: (255, 255, 255) - since white is the presence of all colors. We then combine these values into an RGB tuple in the form (red, green, blue). Given that the pixel value only needs to be in the range, we normally use an 8-bit unsigned integer to represent each color intensity. Other color spaces exist (HSV (Hue, Saturation, Value), L*a*b*, etc.), but let’s start with the basics and move our way up from there.Įach of the three Red, Green, and Blue colors are represented by an integer in the range from 0 to 255, which indicates how “much” of the color there is. The grayscale gradient image in Figure 2 demonstrates darker pixels on the left-hand side and progressively lighter pixels on the right-hand side.Ĭolor pixels, however, are normally represented in the RGB color space - one value for the Red component, one for Green, and one for Blue leading to a total of 3 values per pixel: In a grayscale image, each pixel has a value between 0 and 255, where 0 corresponds to “black” and 255 being “white.” The values between 0 and 255 are varying shades of gray, where values closer to 0 are darker and values closer 255 are lighter: Figure 2: Image gradient demonstrating pixel values going from black (0) to white (255). Let’s look at the example image in Figure 1: Figure 1: This image is 600 pixels wide and 450 pixels tall for a total of 600 x 450 = 270,000 pixels. If we think of an image as a grid, each square in the grid contains a single pixel. Normally, a pixel is considered the “color” or the “intensity” of light that appears in a given place in our image. There is no finer granularity than the pixel. Pixels are the raw building blocks of an image. We’ll wrap up this tutorial with a discussion of our results. As the name suggests, this allows us to access and manipulate pixels using OpenCV. With our project directory structure reviewed, we’ll implement a Python script, opencv_getting_setting.py. We’ll also review the image coordinate system in OpenCV, including the proper notation to access individual pixel values.įrom there, we’ll configure our development environment and review our project directory structure. In the first part of this tutorial, you will discover what pixels are (i.e., the building blocks of an image).
#Red color on linux 255 255 255 code
Looking for the source code to this post? Jump Right To The Downloads Section OpenCV Getting and Setting Pixels
