Skip to content

matdomis/image-processor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image Filters

This project aims to build simple filters for digital images in gray levels, in PGM format (P2 and P5) with 8-bit pixels (1 byte).

Compiling the Program

Clone the repository

git clone [email protected]:matdomis/image-processor.git

Compile the files with the command make:

make all

Negative Filter

The negative filter consists of converting each pixel in the image into its complement. If max is the maximum value for a pixel in the image, the complement of a pixel with value v would be max-v.

Calling method:

pgmnega -i input -o output

Example of input and output:

Image 1 Image 2

Simple rotation filter

The rotation filter rotates an image 90° clockwise.

Calling format:

pgmrotacao -i input -o output

Example of input and output:

Image 1 Image 2

Free rotation filter

The rotation filter rotates an image clockwise by an angle θ (>0) relative to its center (see 2D image rotation).

Requirements:

  • The size of the output image must be adjusted so as not to cut the corners of the image.
  • The empty spaces generated by the rotation must be filled with white.
  • The rotation angle is informed by the -a option; if not informed, by default θ = 90º.

Calling format:

pgmrotacao -a N -i input -o output

Example of input and output for θ = 30º:

Image 1 Image 2

Threshold filter

The threshold filter converts a grayscale image into a black-and-white (2-color) image. The simplest way to do this is to compare the value of each pixel with a predefined threshold: if the pixel value is equal to or greater than the threshold, it turns white (v=max), otherwise it turns black (v=0).

Invocation form:

pgmthreshold -l N -i input -a output

where N is a real threshold between 0.0 (0% of the maximum value) and 1.0 (100% of the maximum value). If the threshold is not defined, it is assumed to be 50%.

Example of input and outputs with thresholds of 50% and 75%:

| Image 1 | Image 2 | Image 3 | |-------------------------|-------------------------|

Noise reduction filter by averaging

The averaging filter is used to “clean” an image, that is, to reduce its noise level. The algorithm is basic and very simple: for each pixel, its value must be replaced by the average of all 9 neighboring pixels (including itself).

Special care must be taken when treating pixels in the first and last rows or columns, as they do not have all their neighbors. In these cases, only existing neighbors should be considered in the calculation.

Calling method:

pgmmedia -i input -a output

Example of input and output:

Image 1 Image 2

Median filter

The median filter reduces the noise level of an image without greatly affecting its sharpness. This filter basically consists of replacing the value of a pixel with the median value of its neighboring pixels. The number of neighbors to be considered is defined by a mask, that is, the matrix of neighbors that surrounds the pixel to be treated (including itself):

Image

Requirements:

  • The size of the mask is an odd positive integer, which can be specified on the command line (-m option); if not specified, the default value is 3, for a 3×3 pixel mask.
  • The pixels on the edges of the image do not have all their neighbors and therefore should not be filtered.
  • To sort the pixel values, the qsort function from the C library (man qsort) must be used.

Calling method:

pgmmediana -m N -i input -o output

Example of input and output:

Image 1 Image 2

About

An image processor built in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published