Filter is a program that applies various filters to 24-bit BMP (Bitmap) images. It supports grayscale, sepia, reflection, and blur filters. The program processes the image pixel by pixel and generates a new image file with the applied effect.
By modifying the RGB values in the pixels of a BMP file, Filter demonstrates image manipulation through low-level programming in C.
- Grayscale: Converts an image to black-and-white shades.
- Sepia: Applies an old-timey, reddish-brown filter.
- Reflection: Mirrors the image horizontally.
- Blur: Applies a box blur to smooth the image.
Before using Filter, ensure you have the following:
- A C compiler (
clangorgcc). makebuild tool.
Follow these steps to install them based on your operating system:
- Update your package list:
sudo apt update
- Install Clang and Make:
sudo apt install clang make
- Verify installation:
clang --version make --version
- Install Xcode Command Line Tools:
xcode-select --install
- Verify installation:
clang --version make --version
- Download the LLVM installer from the official LLVM website.
- Run the installer and follow the setup instructions.
- Add the LLVM
bindirectory (e.g.,C:\Program Files\LLVM\bin) to your system'sPATHenvironment variable:- Open "Environment Variables" in Windows settings.
- Edit the
Pathvariable and add the directory.
- Install
Makevia Chocolatey or MinGW. - Verify installation:
clang --version make --version
Use the provided Makefile to compile the program:
make filterThis will generate an executable file named filter.
Run the program using the following syntax:
./filter [FILTER_OPTION] infile.bmp outfile.bmp-g: Apply grayscale filter.-s: Apply sepia filter.-r: Apply reflection filter.-b: Apply blur filter.
- infile.bmp: Path to the input BMP file.
- outfile.bmp: Path where the filtered image will be saved.
./filter -g images/yard.bmp out.bmp./filter -s images/yard.bmp out.bmp./filter -r images/yard.bmp out.bmp./filter -b images/yard.bmp out.bmp├── filter/
│ ├── helpers.h
│ ├── helpers.c
│ ├── Makefile
│ ├── images/
│ │ ├── courtyard.bmp
│ │ ├── stadium.bmp
│ │ ├── yard.bmp
│ │ └── tower.bmp
│ ├── filter.c
│ ├── bmp.h
└── README.md
helpers.h: Function prototypes for the filters.helpers.c: Implements the grayscale, sepia, reflection, and blur filters.filter.c: Main program logic for applying filters and handling BMP files.bmp.h: Defines data structures and types for BMP file handling.Makefile: Automates the build process.images/: Sample BMP files for testing.
Converts an image to black-and-white shades by averaging the red, green, and blue values for each pixel. The resulting value is applied to all three color channels.
Applies a reddish-brown filter using the following formula:
sepiaRed = .393 * red + .769 * green + .189 * blue
sepiaGreen = .349 * red + .686 * green + .168 * blue
sepiaBlue = .272 * red + .534 * green + .131 * blue
Values exceeding 255 are capped at 255.
Reflects the image horizontally by swapping pixels on the left side with those on the right side for each row.
Applies a box blur by averaging the RGB values of a pixel and its neighbors in a 3x3 grid. Edge pixels use only available neighbors.
- Dependencies: Standard C libraries (
stdio.h,stdlib.h,math.h). - Compatibility: Works on Unix-like systems (Linux, macOS) and Windows (with MinGW or WSL).
- Manual Compilation: If
makeis unavailable:clang -std=c11 -Wall -Werror -o filter filter.c helpers.c -lm
The images/ directory contains sample BMP files for testing, such as:
yard.bmpcourtyard.bmpstadium.bmp
To test the program, use:
./filter -g images/yard.bmp out.bmpInspect the output image (out.bmp) to confirm the filter was applied correctly.
Developed by Shahir Ahmed.
This project is licensed under the MIT License.