Skip to content

an-sla/image_processor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

BMP Image Processor in C++

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.


Features

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.

Input Format

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.

Available Filters

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 * B

3. 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 -B

4. 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).


Getting Started

Instructions to install and test this project locally.

Prerequisites

  • C++ Compiler β€” must support at least the C++17 standard, i.e. MSVC, GCC, Clang

Installing

  • Clone this GitHub repository by running:
git clone https://github.com/an-sla/image_processor.git

Building

  • Use CMake settings or the following command-line arguments in the image_processor directory 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

Examples


License

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.


Contributors

Anastasia / an-sla

Linkedin

About

🏞️ Desktop editor for BMP-images in C++, 5 filters available

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages