https://github.com/raphaelsenn/pixelzauber
Implementing a bunch image processing algorithms for .PGM files from scratch in C++.
https://github.com/raphaelsenn/pixelzauber
Last synced: 12 months ago
JSON representation
Implementing a bunch image processing algorithms for .PGM files from scratch in C++.
- Host: GitHub
- URL: https://github.com/raphaelsenn/pixelzauber
- Owner: raphaelsenn
- License: mit
- Created: 2025-05-16T15:38:01.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-03T13:43:44.000Z (about 1 year ago)
- Last Synced: 2025-06-04T00:36:10.804Z (about 1 year ago)
- Language: C++
- Homepage:
- Size: 4.97 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pixelzauber
Implementing a bunch image processing algorithms for .PGM and .PPM files from scratch in C++.
## Kernels (Filters)
All images shown were produced as outputs of image processing algorithms implemented in this repository.
| Operation | Kernel | Output Image |
|-----------------|-----------------------------------------------|----------------------------------|
| Identity | `[ [0 0 0], [0 1 0], [0 0 0] ]` |  |
| Box Blur | `1/9*[ [1 1 1], [1 1 1], [1 1 1] ]` |  |
| Sharpen | `[ [0 -1 0], [-1 5 -1], [0 -1 0] ]` |  |
| Edge Detection X-Direction | `[ [-1, 0, 1], [-2, 0, 2], [-1, 0, 1] ]` |  |
| Edge Detection Y-Direction | `[ [-1, -2, -1], [0, 0, 0], [1, 2, 1] ]` |  |
```c++
#include "./src/Mat2d.hpp"
int main() {
// loading lena
Mat2d lena;
lena.readPGM("lena.pgm");
// defining a kernel for sharpening
Mat2d kernel = Mat2d({
{0, -1, 0},
{-1, 5, -1},
{0, -1, 0}});
Mat2d lena_sharp = applyFilter(lena, kernel).clip(0, lena.maxVal());
lena_sharp.writePGM("lena_sharp.pgm");
return 0;
}
```
## Synthetic Noise
All images shown were produced as outputs of image processing algorithms implemented in this repository.
| Noise | Output Image |
|------------|----------------------------------|
| Original Image |  |
| Additive gaussian noise with mean = 0, standard deviation = 20 |  |
```c++
#include "./src/Mat2d.hpp"
int main() {
Mat2d lena;
lena.readPGM("./pgm/lena.pgm");
Mat2d noise = Mat2d::normal(0, 20, lena.rows(), lena.cols());
noise.print();
Mat2d lena_noise = (lena + noise).clip(0, lena.maxVal());
lena_noise.writePGM("lena_gaussian_noise.pgm");
}
```
## Image Difference
Let $I^{(1)}$, $I^{(2)}$ $\in \mathbb{R}^{N}_{+}$ be two gray scale images. The difference of $I^{(1)}$, $I^{(2)}$ can be defined as:
$$
I^{(1)} - I^{(2)} \coloneqq \left| I^{(1)} - I^{(2)} \right|
$$
The difference of two images can be used to detect moving objects in a static scene.
#### Example: Detecting Moving Objects in a static Scene
Left: Image I1, Middle: Image I2, Right: Absolute difference |I1 − I2| between Image I1 and Image I2
| Noise | Output Image |
|------------|----------------------------------|
| Image I1 |  |
| Image I2 |  |
| Difference of I1 and I2|  |
Image taken from University of Southern California,
"motion05.512 and motion06.512",
https://sipi.usc.edu/database/database.php?volume=sequences
```c++
#include "./src/Mat2d.hpp"
int main() {
Mat2d frame_1;
Mat2d frame_2;
frame_1.readPGM("./pgm/motion05.pgm");
frame_2.readPGM("./pgm/motion06.pgm");
Mat2d diff = (frame_1 - frame_2).clip(0, frame_1.maxVal());
diff.writePGM("motion_difference.pgm");
}
```
## Thresholding
Thresholding is the simplest way to segment an image by converting an intensity image into a binary image based on a threshold value.
| Description | Image |
|------------|----------------------------------|
| Original image |  |
| The binary image resulting from a thresholding of the original image with threshold value of 125. |  |
```c++
#include "./src/Mat2d.hpp"
#include "./src/Segmentation.hpp"
int main() {
Mat2d lena;
lena.readPGM("./pgm/lena.pgm");
Mat2d lena_threshold = thresholding(lena, 125);
lena_threshold.writePGM("lena_threshold.pgm");
return 0;
}
```
## Citations
```bibtex
@misc{lena_image,
title = {Lena Image},
note = {Accessed: 1972},
}
```