Skip to content

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.

License

Notifications You must be signed in to change notification settings

heshanera/IProc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 

Repository files navigation

IProc

license    language    library    library    library   

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

struct RGBApixel {
    unsigned char r = 0;
    unsigned char g = 0;
    unsigned char b = 0;
    unsigned char a = 0;
};
struct ImageDataStruct {
    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

IProc ip;
ip.readImage("path/to/source/file.jpg");

getting the pixel value

// pixel in the position (x, y)
RGBApixel pix = ip.getPixel(10,10);

set a pixel value

// set the pixel at position (x, y)
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

ImageDataStruct imgData;
imgData = ip.getImageDataStruct();
// printing the height and width of the image
std::cout<<"Image height: "<<imgData.imgHeight;
std::cout<<"Image width: "<<imgData.imgWidth;

resize the image

// resize the image (width, height)
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

// crop the image (row1, col1, row2, col2);
imgData.crop(20,30,80,100);

get the grayscale pixels of the image

// convert the RGB values to grayscale intensity values
imgData.grayscale();

get the binary pixel map of the image

// convert the image in to a binary image (grayscale intensity value)
imgData.binary(125);

write image to a target file

// write image to a given path
imgData.writeImage("path/to/target/file.png");

Example

#include <libiproc.h>
#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("<<x<<","<<y<<") = "
                <<"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: "<<img.imgHeight;
    std::cout<<"\n";
    std::cout<<"image width: "<<img.imgWidth;
    
    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
architecture architecture architecture architecture

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published