Contributed by < Eric Lin >
Images are made up of tiny dots called pixels, and each pixel can have a different color. In black-and-white images, we use 1 bit for each pixel, where 0 represents black and 1 represents white. For colorful images, more bits are needed per pixel. Formats like BMP, JPEG, or PNG with "24-bit color" use 24 bits per pixel. In a 24-bit BMP, 8 bits represent the amount of red, 8 bits for green, and 8 bits for blue in a pixel's color. This combination of red, green, and blue is known as RGB color.
For more information, please refer bitmaps.
Filtering an image means altering each pixel of an original image to create a specific effect in the resulting image. It involves modifying the pixels to achieve a desired outcome.
The following filters are included in this project:
This structure describes a color consisting of relative intensities of red, green, and blue.
To create a grayscale filter for an image, we aim to convert it to black-and-white. This is achieved by ensuring that the red, green, and blue values of each pixel are the same.
To determine the grayscale value for a pixel, we take the average of its red, green, and blue values. This helps maintain the overall brightness or darkness of the image.
The "reflect" filter mirrors the original image, creating a result as if you placed the original in front of a mirror. In this filter, pixels on the left side of the image move to the right, and vice versa.
The reflection effect is achieved by rearranging the placement of the existing pixels rather than introducing new ones.
To achieve a blurred or softened effect in an image, one method is the "box blur." This technique involves taking each pixel and, for each color value, assigning it a new value by averaging the color values of neighboring pixels.
In the context of a 3x3 box around each pixel, the new value of a pixel is the average of the color values of all pixels within 1 row and column of the original pixel.
For more information, please refer blur.
The Sobel operator achieves edges detection by modifying each pixel based on its 3x3 pixel grid surroundings. Unlike simple averaging, the Sobel operator calculates a weighted sum of surrounding pixels. It computes two sums: one for detecting edges in the x-direction and one for the y-direction, using specific kernels.
source: cs50:filter
The kernels are designed to emphasize differences in color between neighboring pixels. For instance, in the Gx direction, pixels to the right are multiplied by a positive number, and those to the left by a negative number. This amplifies differences, indicating potential object boundaries. A similar principle applies to the y-direction.
To generate Gx and Gy values for each color channel of a pixel, the original color values in the 3x3 box are multiplied by corresponding kernel values through the convolution operation:
source: wikipedia: Convolution
The Sobel filter combines Gx and Gy into a final value by calculating the square root of Gx^2 + Gy^2.
source: wikipedia: Sobel_operator