Skip to content

vvauijij/image_processor

Repository files navigation

Graphic filters (image_processor)

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 .

Format of command line arguments

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] ...] ...

Example

This is original image:

original

Let us apply these filters:

./image_processor examples/original.bmp examples/example.bmp -crop 1100 1200 -gs -blur 0.5 -neg

In this example

  1. The image is loaded from the file examples/original.bmp
  2. Cropped to an image with the beginning in the upper left corner and a size of 1100x1200 pixels
  3. Converted to grayscale
  4. Blur with sigma 0.5 is applied
  5. A color inverting filter is applied
  6. The resulting image is saved to the file examples/example.bmp

Our result here is following:

example

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.

Filters

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.

List of basic filters

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

encoding

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:

crop result

Grayscale (-gs)

Converts the image to grayscale using the formula

encoding

Command: -gs Result:

greyscale result

Negative (-neg)

Converts an image to a negative using the formula

encoding

Command: -neg Result:

negative result

Sharpening (-sharp)

Sharpening. It is applied by using a matrix

encoding

Command: -sharp Result:

sharpening result

Edge Detection (-edge threshold)

Border selection. The image is converted to grayscale and a matrix is applied

encoding

Pixels with a value exceeding the threshold are colored white, the rest are black.

Command: -edge 0.15 Result:

edge detection 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

encoding

Command: -blur 3 Result:

Gaussianl blur 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:

bilateral result

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published