IProc
A dynamic library for image processing. To Extract the pixel map of the image. Support PNG, JPG, TIF and BMP image file formats. Inbuilt methods for resizing, cropping, generating grayscale and binary images.
Data Structures
RGBAPixel
ImageDataStruct
unsigned char r = 0;
unsigned char g = 0;
unsigned char b = 0;
unsigned char a = 0;
};
RGBApixel * imgPixArray;
int imgWidth;
int imgHeight;
};
Methods
int readImage(std::string);
int writeImage(std::string);
RGBApixel getPixel(int,int);
ImageDataStruct getImageDataStruct();
int setPixel(int,int,RGBApixel);
int setImageDataStruct(ImageDataStruct);
int resizeImage(int, int);
int crop(int, int, int, int);
int binary(int);
int grayscale();
reading the image file
ip.readImage("path/to/source/file.jpg");
getting the pixel value
RGBApixel pix = ip.getPixel(10,10);
set a pixel value
RGBApixel pix;
pix.r = 100;
pix.g = 100;
pix.b = 100;
pix.a = 255;
ip.setPixel(10,15,pix);
get the pixel map of the image
imgData = ip.getImageDataStruct();
// printing the height and width of the image
std::cout<<"Image height: "<
resize the image
imgData.resizeImage(100,20);
// resize the image (width, auto)
imgData.resizeImage(100,-1);
// resize the image (auto, height)
imgData.resizeImage(-1,20);
crop the image
imgData.crop(20,30,80,100);
get the grayscale pixels of the image
imgData.grayscale();
get the binary pixel map of the image
imgData.binary(125);
write image to a target file
imgData.writeImage("path/to/target/file.png");
Example
#include <iostream>
int main() {
IProc ip;
ip.readImage("imgs/JPEG/input/img5.jpg");
int x = 10, y = 10;
RGBApixel pixel = ip.getPixel(x, y);
std::cout <<"Image("<
<<"RGBA( "
<<(int)pixel.r<<" "
<<(int)pixel.g<<" "
<<(int)pixel.b<<" "
<<(int)pixel.a<<" "
<<")\n";
ip.setPixel(10,15,pixel);
ImageDataStruct img = ip.getImageDataStruct();
std::cout<<"image height: "<
std::cout<<"\n";
std::cout<<"image width: "<
ip.writeImage("imgs/PNG/output/img1.png");
ip.readImage("imgs/JPEG/input/img5.jpg");
ip.grayscale();
ip.writeImage("imgs/PNG/output/img2.png");
ip.readImage("imgs/JPEG/input/img5.jpg");
ip.binary(180);
ip.writeImage("imgs/PNG/output/img3.png");
ip.readImage("imgs/JPEG/input/img5.jpg");
ip.resize(100,100);
ip.writeImage("imgs/PNG/output/img4.png");
return 0;
}
Output
>> Image(10,10) = RGBA( 255 255 255 255 )
>> image height: 250
>> image width: 250
| Original | Grayscale | Binary | Resized |
|---|---|---|---|