Skip to content

Pure C image processing library - Learn DFT/FFT, convolution, edge detection from scratch. Zero dependencies, perfect for embedded systems.

License

Notifications You must be signed in to change notification settings

uzunenes/piciem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Piciem

Pure C Image Processing Library - Learn from Scratch

A lightweight, educational image processing library in pure C with zero external dependencies. Perfect for learning DFT/FFT, convolution, edge detection, morphology, and frequency domain filtering from scratch.

Why Piciem?

  • Educational - Clean, readable code with examples
  • Lightweight - No OpenCV, no NumPy, just standard C library
  • Learn by doing - Build algorithms, don't just use them
  • Embedded-friendly - Small footprint, easy to port

Examples

Original

Basic Operations

Brightness (+50) Contrast (×1.5) Invert

Thresholding

Simple (t=128) Otsu

Enhancement & Edge Detection

Histogram Equalization Sobel

Frequency Domain

DFT (4.39s) FFT (0.02s)

Homomorphic Filtering

Input Output
Input Output

Parameters: D0=30, γL=0.8, γH=1.5, n=2

Filters & Noise

Original Gaussian Blur Noisy (5%) Median Denoised

Frequency Filters

Original Low Pass (Butterworth, cutoff=30)

Low pass filter attenuates high frequencies, resulting in a smoothed/blurred image.

Morphology

Binary Eroded Dilated
Opening Closing

Functions

I/O

  • lpgm_file_read() - Read PGM (P2/P5)
  • lpgm_file_write() - Write PGM

Basic

  • lpgm_brightness() - out = in + δ
  • lpgm_contrast() - out = (in-128)×α + 128
  • lpgm_invert() - out = 255 - in
  • lpgm_threshold() - Binary threshold
  • lpgm_otsu_threshold() - Automatic threshold

Filters

  • lpgm_convolve() - NxN kernel convolution
  • lpgm_median_filter() - Median filter
  • lpgm_add_salt_pepper_noise() - Add noise
  • lpgm_gamma() - Gamma correction

Enhancement

  • lpgm_histogram_equalization() - Histogram equalization
  • lpgm_sobel() - Edge detection

Frequency Domain

  • lpgm_dft() / lpgm_dft2() - DFT, O(n²)
  • lpgm_fft() / lpgm_fft2() - FFT, O(n log n)
  • lpgm_filter_ideal_lowpass/highpass() - Ideal filter
  • lpgm_filter_butterworth_lowpass/highpass() - Butterworth filter
  • lpgm_filter_gaussian_lowpass/highpass() - Gaussian filter

Morphology

  • lpgm_erode() - Erosion
  • lpgm_dilate() - Dilation
  • lpgm_opening() - Opening (erosion + dilation)
  • lpgm_closing() - Closing (dilation + erosion)

Build

git clone https://github.com/uzunenes/piciem.git
cd piciem
make
sudo make install

Usage

cd examples/edge_detection
make
./sobel.out ../pgm_io/lena_ascii.pgm

Structure

piciem/
├── include/pigiem.h
├── src/
│   ├── pgm_io.c
│   ├── image.c
│   ├── dft.c
│   ├── fft.c
│   └── utils.c
├── examples/
│   ├── basic_operations/
│   ├── thresholding/
│   ├── filters/
│   ├── noise/
│   ├── histogram/
│   ├── edge_detection/
│   ├── frequency_domain/
│   ├── frequency_filters/
│   ├── morphology/
│   └── homomorphic_filtering/
└── docs/images/

Example Code

#include <pigiem.h>

int main(void)
{
    lpgm_t pgm;
    lpgm_image_t edges;
    
    lpgm_file_read("input.pgm", &pgm);
    edges = lpgm_sobel(&pgm.im);
    
    pgm.im = edges;
    lpgm_file_write(&pgm, "output.pgm");
    
    lpgm_image_destroy(&edges);
    lpgm_file_destroy(&pgm);
    return 0;
}
gcc -o example example.c -lpigiem -lm

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

Support

If you find this library useful for learning image processing, please consider giving it a star!

License

MIT