This is an image-editor built with C++ for applying filters to bitmap files.
5 filters are realised. The program supports 24-bit BMPs with RGB24 pixel format, no data compression or colour profiles, and with a DIB header of type BITMAPINFOHEADER. The image format corresponds to this example.
The program returns an image in the same 24-bit BMP format with one or more out of 5 available filters applied to it. If no filter argument is provided, the program returns the original image. If multiple filter arguments are given, the filters are applied consecutively.
Each pixel colour is represented by a 1x3 vector of values between 0 and 1, corresponding to its (R, G, B) markers. (0, 0, 0) represents black and (1, 1, 1) represents white. Some of the filters apply a matrix to each of the pixel's colours by using input from its surrounding pixels β thus, in the 'Sharpening' and 'Edge' filters, a pixel's colours are influenced by the 8 pixels surrounding it (directly above, on each side, and below). When a given pixel lies in a corner or at the border of the image, only non-empty / existing surrounding pixels are used to calculate its new values.
The program accepts input in the form:
{program name} {path to input.bmp} {path to output.bmp} [-{filter 1} [param 1] [param 2]...] [-{filter 2} [param 1] [param 2]...]...
Note the dash in front of the filter name. If no filter arguments are provided where they are needed or if the parameter format and number of parameters does not correspond to the filter name, the program returns an error message with instructions of what to include.
1. Crop -crop width height
Crops the image to the given width and height. The upper-left corner of the image is used as the starting point. If the height or the width parameters exceed the original image size, the entire available original image is returned.
2. Grayscale -gs
Converts the image to greyscale, based on the formula:
- R' G' B' are new values, R, G, B are original values for each pixel -
R' = B' = G = 0.299 * R + 0.587 * G + 0.114 * B3. Negative -neg
Inverts the image colours to a negative scale, based on the formula:
- R' G' B' are new values, R, G, B are original values for each pixel -
R' = 1 - R
G' = 1 - G
B' = 1 -B4. Sharpening -sharp
Enhances image sharpness, the following matrix is applied:
- the value of each pixel is multiplied by the matrix: -
0 β1 0
β1 5 β1
0 β1 0
- thus, E is the new matrix and A is the original β
E[x][y] =
0 * A[x-1][y-1] + (-1) * A[x][y-1] + 0 * A[x+1][y-1] +
(-1) * A[x-1][y] + 5 * A[x][y] + (-1) * A[x+1][y] +
0 * A[x-1][y+1] + (-1) * A[x][y+1] + 0 * A[x+1][y+1]5. Edge Detection -edge threshold
Selects and highlights edges. The image is converted to greyscale and the following matrix is applied:
- the value of each pixel is multiplied by the matrix: -
0 β1 0
β1 4 β1
0 β1 0
- thus, E is the new matrix and A is the original β
E[x][y] =
0 * A[x-1][y-1] + (-1) * A[x][y-1] + 0 * A[x+1][y-1] +
(-1) * A[x-1][y] + 4 * A[x][y] + (-1) * A[x+1][y] +
0 * A[x-1][y+1] + (-1) * A[x][y+1] + 0 * A[x+1][y+1]Pixels whose values after this multiplication exceed the given threshold argument are coloured white (1, 1, 1), the rest are coloured black (0, 0, 0).
Instructions to install and test this project locally.
- C++ Compiler β must support at least the C++17 standard, i.e. MSVC, GCC, Clang
- Clone this GitHub repository by running:
git clone https://github.com/an-sla/image_processor.git
- Use CMake settings or the following command-line arguments in the
image_processordirectory to build the project:
- shown for g++ and the C++17 standard -
g++ -std=c++17 -o image_processor image_processor.cpp controller.cpp file_work.cpp filters.cpp- Then use the command line to input arguments and apply filters as described above:
- shown for lena.bmp, negative filter -
./image_processor input-bmp_files/input-lena.bmp negative_results/output.bmp -neg- Sample images are available in the input-bmp_files directory, expected results with the given parameters are provided in the crop, greyscale, negative, sharpening, and edge directories.
- The source images for this project listed in the input-bmp_files directory have been taken from:
- FileFormat.Info under the Creative Commons Attribution-Share Alike 3.0 United States License;
- The University of Southern Carolina BMP Files page under the the GNU LGPL license;
- The HSE University GitLab Repository for this project, originally by Dwight Hooker, copyrighted, and distributed under the 'Fair Use' exception to US copyright law.
These have been modified with the program's filters for demonstration and educational purposes.
This project is licensed under the GNU General Public License 3.0.
Anastasia / an-sla