Implementation of a console application that allows you to apply various filters to images in 24-bit BMP format, similar to the filters in popular graphics editors.
This .md page takes a while to load the example pictures from ./examples folder .
Description of the format of command line arguments:
{program name} {path to input file} {path to output file} [-{filter name 1} [filter parameter 1] [filter parameter 2] ...] [-{filter name 2} [filter parameter 1] [filter parameter 2] ...] ...
This is original image:
Let us apply these filters:
./image_processor examples/original.bmp examples/example.bmp -crop 1100 1200 -gs -blur 0.5 -neg
In this example
- The image is loaded from the file
examples/original.bmp
- Cropped to an image with the beginning in the upper left corner and a size of 1100x1200 pixels
- Converted to grayscale
- Blur with sigma 0.5 is applied
- A color inverting filter is applied
- The resulting image is saved to the file
examples/example.bmp
Our result here is following:
The filter list may be empty, then the image must be saved unchanged. Filters are applied in the order in which they are listed in the command line arguments.
In the formulas, we further assume that each color component
is represented by a real number from 0 to 1. Pixel colors
are represented by triples (R, G, B)
. Thus, (0, 0, 0)
– black,
(1, 1, 1)
– white.
Matrix filter (no user-usage due to it is inside component of the project)
If the filter is set by a matrix, it means that the value of each of the colors is determined by the weighted sum of the values of this color in neighboring pixels in accordance with the matrix. In this case, the target pixel corresponds to the central element of the matrix.
For example, for a filter given by a matrix
The value of each of the colors of the target pixel C[x][y]
will be determined by the formula
C[x][y] =
min(1,
max(0,
1*C[x-1][y-1] + 2*C[x][y-1] + 3*C[x+1][y-1] +
4*C[x-1][y] + 5*C[x][y] + 6*C[x+1][y] +
7*C[x-1][y+1] + 8*C[x][y+1] + 9*C[x+1][y+1]
)
)
When processing pixels close to the edge of the image, part of the matrix may extend beyond the image boundary. In this case, we will use the value of the image pixel closest to it as the value of the pixel that goes beyond the border.
Crop (-crop width height)
Crops the image to the specified width and height. The upper left part of the image is used.
If the requested width or height exceeds the dimensions of the original image, the available part of the image is given.
Command: -crop 1100 1800
Result:
Grayscale (-gs)
Converts the image to grayscale using the formula
Command: -gs
Result:
Negative (-neg)
Converts an image to a negative using the formula
Command: -neg
Result:
Sharpening (-sharp)
Sharpening. It is applied by using a matrix
Command: -sharp
Result:
Edge Detection (-edge threshold)
Border selection. The image is converted to grayscale and a matrix is applied
Pixels with a value exceeding the threshold are colored white, the rest are black.
Command: -edge 0.15
Result:
Gaussian Blur (-blur sigma)
Gaussian blur, the parameter is sigma.
The value of each of the pixel colors C[x0][y0]
is determined by the formula
Command: -blur 3
Result:
Bilateral (-bilateral sigma_r sigma_s)
Filter replaces the intensity of each pixel with a weighted average of intensity values from nearby pixels. This weight can is based on a Gaussian distribution. Crucially, the weights depend not only on Euclidean distance of pixels, but also on the color intensity. This preserves sharp edges.
Command: -bilateral 20 30
Result: