Skip to content

A C++14 implementation of image processing algorithms.

Notifications You must be signed in to change notification settings

MatHermann/Images-Processing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image processing algorithms

List of implemented algorithms

Quick example

#include <iostream>  
#include "Image.h"  
#include "Filter.h"  
#include "helpers.h"  
  
int main()  
{  
    Image image = Image::fromFile("image.pgm");  
    Filter gFilter = Filter::GAUSS(5); // Gaussian filter 5x5  
    Image filteredImage = image*gFilter;  
  
    image.transformLinear().save("image-linear.pgm");  
    image.binarize().save("image-binary.pgm");  
    image.equalizeHistogram().save("image-equalized.pgm");  
    filteredImage.save("image-filtered(gauss 5x5).pgm");  
  
    std::cout << "Done !" << std::endl;  
  
    return 0;  
}

Note

All this was made to work on grayscale images in PGM (version P2) format. If you want to use this on images of other format, you must rewrite these methods:

  • Image::fromFile(std::string filename);
  • Image::save(std::string filename);

Setting

Before working with these files, you must change the prefix (defined in helpers.cpp file. 9th line) to add in images paths.

std::string e(const std::string &filename)  
{  
    return R"(C:\images\)" + filename;  
}

You can replace the "C:\images\" by any other prefix you want, or just return filename if you want to specify full path while loading an image.

Usage

Linear transformation

Image image = Image::fromFile("image.pgm");
Image result = image.transformLinear();
result.save("image-transformLinear.pgm");

Linear transformation with saturation

Image image = Image::fromFile("image.pgm");
Image result = image.transformLinear(100, 200);
result.save("image-transformLinear.pgm");

Histogram equalization

Image image = Image::fromFile("image.pgm");
Image result = image.equalizeHistogram();
result.save("image-equalized.pgm");

Arithmetic operations (ADDITION, SUBTRACTION, MULTIPLICATION)

Image image1 = Image::fromFile("image1.pgm");
Image image2 = Image::fromFile("image2.pgm");
Image _double = 2 * image1;
Image sum = image1 + image2;
Image result = _double - sum;
result.save("arithmetic.pgm");

Nearest neighbor interpolation (zoom)

Image image = Image::fromFile("image.pgm");
Image result = image.nearestNeighbourInterpolation(8); // zoom x 8
result.save("image-zoom x 8.pgm");

Convolution product

Image image = Image::fromFile("image.pgm");
Filter filter = Filter::GAUSS(5); // Gaussian filter 5x5
Image result = image * filter; // Convolution product
result.save("image-filtered(gauss 5x5).pgm");

Gaussian filter

Image image = Image::fromFile("image.pgm");
Filter filter = Filter::GAUSS(5); // Gaussian filter 5x5
Image result = image * filter; // Convolution product
result.save("image-filtered(gauss 5x5).pgm");

Averaging filter

Image image = Image::fromFile("image.pgm");
Filter filter = Filter::AVERAGING(5); // Averaging filter 5x5
Image result = image * filter; // Convolution product
result.save("image-filtered(averaging 5x5).pgm");

Median filter

Image image = Image::fromFile("image.pgm");
Image result = image.median(5); // Median filter 5x5
result.save("image-median.pgm");

Robert's filters

Image image = Image::fromFile("image.pgm");
Filter filter1 = Filter::ROBERT_X();
Filter filter2 = Filter::ROBERT_Y();
Image vImage = image * filter1;
Image hImage = image * filter2;
Image result = hImage + vImage;
result.save("image-filtered(robert).pgm");

Prewitt's filters

Image image = Image::fromFile("image.pgm");
Filter filter1 = Filter::PREWITT_X();
Filter filter2 = Filter::PREWITT_Y();
Image vImage = image * filter1;
Image hImage = image * filter2;
Image result = hImage + vImage;
result.save("image-filtered(prewitt).pgm");

Sobel's filters

Image image = Image::fromFile("image.pgm");
Filter filter1 = Filter::SOBEL_X();
Filter filter2 = Filter::SOBEL_Y();
Image vImage = image * filter1;
Image hImage = image * filter2;
Image result = hImage + vImage;
result.save("image-filtered(sobel).pgm");

Laplace's Filters

Image image = Image::fromFile("image.pgm");
Filter filter1 = Filter::LAPLACE1();
Filter filter2 = Filter::LAPLACE2();
Image result1 = image * filter1;
Image result2 = image * filter2;
result.save("image-filtered(laplace1).pgm");
result.save("image-filtered(laplace2).pgm");

Segmentation in 2 classes: Otsu's algorithm

Image image = Image::fromFile("image.pgm");
Image result = image.binarize();
result.save("image-binary.pgm");

Logical operations (NOT, AND, OR, XOR)

Image image1 = Image::fromFile("image1.pgm");
Image image2 = Image::fromFile("image2.pgm");
Image _not = !image1; // Not
Image _and = _not && image2; // And
Image _or = _and || image1; // Or
Image result = _or ^ image2; // Xor
result.save("logical.pgm");

Erosion

Image image = Image::fromFile("image.pgm");
Image result = image.erode(CONNEXITY_4()); // Erode using 4-connexity
result.save("image-eroded.pgm");

Expansion

Image image = Image::fromFile("image.pgm");
Image result = image.erode(CONNEXITY_8()); // Expand using 8-connexity
result.save("image-expanded.pgm");

Opening

Image image = Image::fromFile("image.pgm");
Image result = image.erode(CONNEXITY_8()); // Open using 8-connexity
result.save("image-open.pgm");

Closing

Image image = Image::fromFile("image.pgm");
Image result = image.close(CONNEXITY_4()); // Close using 4-connexity
result.save("image-closed.pgm");

Internal gradient

Image image = Image::fromFile("image.pgm");
Image result = image.internalGradient(CONNEXITY_8());
result.save("image-internalGradient.pgm");

External gradient

Image image = Image::fromFile("image.pgm");
Image result = image.externalGradient(CONNEXITY_4());
result.save("image-externalGradient.pgm");

Morphological gradient

Image image = Image::fromFile("image.pgm");
Image result = image.morphologicalGradient(CONNEXITY_8());
result.save("image-morphologicalGradient.pgm");

About

A C++14 implementation of image processing algorithms.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published