Reputation: 49
I am a Computer Science student and I am stuck on a C++ coursework. I can't seem to find a way to compare pixel of two images and then combine into one. This is the task that I am stuck on at the moment:
Part1:
Load the two image pairs provided that are located in theImages folder: (pair 1: render_top_1 & render_top_2, pair 2: render_bottom_1 & render_bottom_2) Note: You can use the example load function given in lectures and tutorials to load images. For each pair compare their pixels and if the pixels are the same make them black, if they are not make them white. Save the resulting images as "stage1_top.png" for the top pair and "stage1_bottom.png" for the bottom pair. You will need then to combine both of the images "stage1_top" and "stage1_bottom" into a single image. The combination should be an equal split taking 50% of the pixel value from each of the images. Save resulting combined image as "stage1_combined.png"
So far, I managed to load the images and get their width and height and now I think I have to use a double for loop to compare top_1 with top_2 and botto_1 with bottom_2.
This is how I am loading the pictures:
//Pair 1 Loading images
fipImage inputImage_bot1;
inputImage_bot1.load("Images\render_bottom_1.png");
inputImage_bot1.convertToFloat();
fipImage inputImage_top1;
inputImage_top1.load("Images\render_top_1.png");
inputImage_top1.convertToFloat();
fipImage inputImage_bot2;
inputImage_bot2.load("Images\render_bottom_2.png");
inputImage_bot2.convertToFloat();
fipImage inputImage_top2;
inputImage_top2.load("Images\render_top_2.png");
inputImage_top2.convertToFloat();
auto width_bot1 = inputImage_bot1.getWidth();
auto height_bot1 = inputImage_bot1.getHeight();
const float* const inputBuffer_bot1 = (float*)inputImage_bot1.accessPixels();
auto width_bot2 = inputImage_bot2.getWidth();
auto height_bot2 = inputImage_bot2.getHeight();
const float* const inputBuffer_bot2 = (float*)inputImage_bot2.accessPixels();
auto width_top1 = inputImage_top1.getWidth();
auto height_top1 = inputImage_top1.getHeight();
const float* const inputBuffer_top1 = (float*)inputImage_top1.accessPixels();
auto width_top2 = inputImage_top2.getWidth();
auto height_top2 = inputImage_top2.getHeight();
const float* const inputBuffer_top2 = (float*)inputImage_top2.accessPixels();
I tried using a for loop to compare the pixels:
for (int i = 0; i < width_bot1; i++)
{
for (int j = 0; j < width_bot2; j++)
{
if (inputImage_bot1[i][j] == inputImage_bot2[i][j])
{
//comparison code here
}
}
}
I receive the following error:
no operator "[]" matches these operands
opearand types are: FIBITMAP [ int ]
I can only use FreeImagePlus library and I am completly lost with it. How can I compare the pixels of the two pictures and then save 50% of each in a different file?
Upvotes: 0
Views: 1128
Reputation: 6805
By looking at the documentation of the fipImage
class, there is no defined operator[]
overload for this class. Therefore you cannot access pixels this way.
If we pay more attention to the documentation, we can find the methods fipImage::getPixelIndex()
and fipImage::getPixelColor
(and their set variants by the way) which seem to do what you seek.
Usage example:
// We assume:
// - We have a fipImage instance called my_image.
// - We want to get the pixel color at position (x,y)
RGBQUAD color;
if(my_image.getPixelColor(x, y, &color))
{
// color now contains the color at position (x,y).
}
Details about the RGBQUAD
structure can be found here.
Upvotes: 2