Hi guys, I need assistance in this. I am supposed to make a function:combineImage(const Image & im, int I, int j): that combines two images together, The position of the image to insert is specified such that the upper left pixel of im is located on row i and column j. Note that i and j could be outside of the image we are combing with. Use a blending operation where the combined images overlap. A blending operation averages the overlapping pixel values. Note that each color for each pixel must be averaged separately. Because the combined image must be rectangular we may have empty portions in the final image. The pixels in the empty portions should be black. For example suppose we have an image of size 200 x 300 pixels and we combine this with an image of size 200 x 100 at location i=10 and j=1. The size of the combined image will be 210 x 300 pixels and the combined image will contain empty black regions.
Here is my code if it helps:( I do really appreciate it if u managed to help!)
// Functions for reading and writing a binary ppm image file
// The image is stored in an array of pixels using integers for the colors
void Picture::load(string imageName){
// read an image from a .ppm file
// returns the image in an array of pixels
// returns the size of the image in width and height
ifstream imageFile;
string s;
char *temp;
int numLevels;
// ios::binary because it is a data file
imageFile.open(imageName.c_str(), ios::binary);
// read in the ppm header
imageFile >> s;
if (s != "P6") {
cout << "Not a valid PPM image" << endl;
}
// read in the image data to temp
imageFile.read(temp,width*height*3);
// copy temp to an array of pixels
image = new pixel[width*height];
for (int i=0; i<width*height; i++) {
unsigned char red = temp[i*3];
unsigned char green = temp[i*3+1];
unsigned char blue = temp[i*3+2];
image[i].red = red;
image[i].green = green;
image[i].blue = blue;
}
delete temp; // return the memory
imageFile.close();
}
void Picture::save(string imageName) {
// store image (array of pixels) in a .ppm file
// widht and height are the size of the input image
ofstream imageFile;
// ios::binary because it is a data file
imageFile.open(imageName.c_str(), ios::binary);
// write the ppm header
imageFile << "P6" << endl << width << endl << height
<< endl << 255 << endl;
char* temp = new char[width*height*3];
// copy the array of pixels in image to temp
for (int i=0; i<width*height; i++) {
char red = image[i].red;
char green = image[i].green;
char blue = image[i].blue;
temp[i*3] = red;
temp[i*3+1] = green;
temp[i*3+2] = blue;
}
// write temp to the file
imageFile.write(temp,width*height*3);
//Then I am supposed to ask the user to input another image to combine it with the existing image
// I really do appreciate it if u managed to help me :)