A command-line image processing tool written in C that applies various filters to images. The program supports multiple image formats (converted to BMP internally) and can download images from URLs.
- Grayscale (-g): Converts color images to grayscale
- Sepia (-s): Applies a warm, vintage sepia tone effect
- Blur (-b): Creates a blur effect using box blur algorithm
- Reflection (-r): Horizontally mirrors the image
- Edge Detection (-e): Detects edges using Sobel operators
- Inversion (-i): Inverts all colors (negative effect)
- Web Image Download (-w): Downloads images directly from URLs
- Format Conversion: Automatically converts non-BMP images to BMP format
- Multiple Format Support: Works with various image formats through stb_image library
curl- for downloading images from URLsstb_image.h- for reading various image formatsstb_image_write.h- for writing image files- Standard C libraries (
stdio.h,stdlib.h,math.h,getopt.h)
sudo apt-get update
sudo apt-get install libcurl4-openssl-devbrew install curlDownload and install curl development libraries from the official curl website.
gcc -o filter filter.c -lcurl -lmMake sure you have the stb_image.h and stb_image_write.h header files in your project directory.
./filter [flag] input_file output_file./filter -w [URL]./filter -g input.jpg output.bmp./filter -s photo.png sepia_photo.bmp./filter -b image.bmp blurred_image.bmp./filter -r photo.jpg reflected_photo.bmp./filter -e landscape.png edges.bmp./filter -i portrait.jpg inverted_portrait.bmp./filter -w https://example.com/image.jpgThe program expects/creates the following directory structure:
./
├── filter (executable)
├── stb_image.h
├── stb_image_write.h
└── images/
├── temp.bmp (temporary conversion file)
└── downloaded_image.* (downloaded images)
Make sure to create the images/ directory before running the program.
- Input Validation: Checks command-line arguments and filter flags
- File Reading: Reads the input image file
- Format Conversion: If the input isn't a 24-bit BMP, converts it using stb_image
- Filter Application: Applies the selected filter algorithm
- Output Writing: Saves the processed image as a BMP file
Converts RGB values to grayscale by averaging the red, green, and blue components.
Applies sepia tone using the standard sepia transformation matrix:
- Red = 0.393R + 0.769G + 0.189*B
- Green = 0.349R + 0.686G + 0.168*B
- Blue = 0.272R + 0.534G + 0.131*B
Uses a box blur algorithm that averages each pixel with its surrounding neighbors.
Implements Sobel edge detection using horizontal and vertical convolution kernels.
Swaps pixels horizontally to create a mirror effect.
Subtracts each color component from 255 to create a negative effect.
The program includes comprehensive error handling for:
- Invalid command-line arguments
- File I/O errors
- Memory allocation failures
- Network download errors
- Unsupported image formats
- Output is always in BMP format
- Requires 24-bit color depth for direct BMP processing
- Web downloads require internet connectivity
- Memory usage scales with image size
0: Success1: Invalid filter flag2: Multiple filters specified3: Incorrect number of arguments4: Cannot open input file5: Cannot create output file7: Insufficient memory
./filter -b vacation.jpg blurred_vacation.bmp# First download
./filter -w https://example.com/photo.jpg
# Then process the downloaded image
./filter -g ./images/downloaded_image.jpg gray_photo.bmp