I have done sequential coding to compare and combine 2 image pairs. After this, I am wanting to write another version using C++11 multi-threading code to make it more efficient.
My sequential code is to follow - does anyone know how I would then begin the C++11 multi-threading version? Many thanks in advance
PARALLEL AND CONCURRENT PROGRAMMING ASSIGNMENT
--------------------------PART 1 - IMAGE COMPARISON ----------------------
//LOAD IMAGE PAIRS
//loading first pair
fipImage inputTop1;
inputTop1.load("render_top_1.png");
fipImage inputTop2;
inputTop2.load("render_top_2.png");
//loading second pair
fipImage inputBottom1;
inputBottom1.load("render_bottom_1.png");
fipImage inputBottom2;
inputBottom2.load("render_bottom_2.png");
unsigned int width = inputTop1.getWidth();
unsigned int height = inputTop1.getHeight();
unsigned int width = inputBottom1.getWidth();
unsigned int height = inputBottom1.getHeight();
float pixels = height*width;
//Outputting images
fipImage renderTopImage = fipImage(FIT_BITMAP, width, height, inputTop1.getBitsPerPixel());
//OR fipImage renderTopImage = fipImage(FIT_BITMAP, width, height, 24);
fipImage renderBottomImage = fipImage(FIT_BITMAP, width, height, inputBottom1.getBitsPerPixel());
//OR fipImage renderBottomImage = fipImage(FIT_BITMAP, width, height, 24);
//getting data from colour of images
vector<vector<RGBQUAD>> rgbValuesOutput;
rgbValuesOutput.resize(height, vector<RGBQUAD>(width));
int white = parallel_reduce(
blocked_range2d<int, int>(0, height, 0, width),
0, //identity value
//process sub-ange setup by TBB - the lambda takes a range and a value parameter which has the
//value of the identity parameter
//Computes the expression over the range, giving a result for that range
//Main lambda to evaluate over the given range
[&](const blocked_range2d<int, int>& range, int value)-> {
auto y1 = range.rows().begin();
auto y2 = range.rows().end();
auto x1 = range.cols().begin();
auto x2 = range.cols().end);
RGBQUAD rgb1;
RGBQUAD rgb2;
//Extracting colour
for(auto y = y1; y < y2; y++){
for(auto x = x1; x < x2; x++){
//comparison of top pair
inputTop1.getPixelColor(x, y, &rgb1);
inputTop2.getPixelColor(x, y, &rgb2);
rgbValuesOutput[y][x].rgbRed = rgb1.rgbRed - rgb2.rgbRed;
rgbValuesOutput[y][x].rgbGreen = rgb1.rgbGreen - rgb2.rgbGreen;
rgbValuesOutput[y][x].rgbBlue = rgb1.rgbBlue - rgb2.rgbBlue;
//Making any pixels from first image pair that are not black into white
if (rgbValuesOutput[y][x].rgbRed != 0 || rgbValuesOutput[y][x].rgbGreen != 0 || rgbValuesOutput[y][x].rgbBlue != 0){
rgbValuesOutput[y][x].rgbRed = 255;
rgbValuesOutput[y][x].rgbGreen = 255;
rgbValuesOutput[y][x].rgbBlue = 255;
value += 1;
}
//Place pixel colour values into output image
renderTopImage.setPixelColor(x, y, &rgbValuesOutput[y][x]);
//Comparison of bottom pair
inputBottom1.getPixelColor(x, y &rgb1);
inputBottom2.getPixelColor(x, y &rgb2);
rgbValuesOutput[y][x].rgbRed = rgb1.rgbRed - rgb2.rgbRed;
rgbValuesOutput[y][x].rgbGreen = rgb1.rgbGreen - rgb2.rgbGreen;
rgbValuesOutput[y][x].rgbBlue = rgb1.rgbBlue - rgb2.rgbBlue;
//Making any pixels from second image pair that are not black into white
if (rgbValuesOutput[y][x].rgbRed != 0 || rgbValuesOutput[y][x].rgbGreen != 0 || rgbValuesOutput[y][x].rgbBlue != 0){
rgbValuesOutput[y][x].rgbRed = 255;
rgbValuesOutput[y][x].rgbGreen = 255;
rgbValuesOutput[y][x].rgbBlue = 255;
value += 1;
}
Place pixel colour values into output image
renderBottomImage.setPixelColor(x, y, &rgbValuesOutput[y][x]);
}
topImage1Pixels += inputTop1.getScanWidth();
topImage2Pixels += inputTop2.getScanWidth();
bottomImage1Pixels += inputBottom1.getScanWidth();
bottomImage2Pixels += inputBottom2.getScanWidth();
}
renderTopImage.save("stage1_top.png");
renderBottom.save("stage1_bottom.png");
//COMBINE BOTH IMAGES INTO SINGLE IMAGE WITH EQUAL SPLIT
BYTE* renderTopPixels = renderTopImage.accessPixels();
BYTE* renderBottomPixels = renderBottomImage.accessPixels();
fipImage combine = fipImage(FIT_BITMAP, width, height, inputBottom1.getBitsPerPixel());
for(auto y = y1; y < y2; y++){
for(auto x = x1; x < x2; x++){
renderTopImage.getPixelColor(x, y, &rgb1);
renderBottomImage.getPixelColor(x, y, &rgb2);
&rgbValuesOutput[y][x].rgbRed = (rgb1->rgbRed + rgb2->rgbRed) * 0.5;
&rgbValuesOutput[y][x].rgbGreen = (rgb1->rgbGreen + rgb2->rgbGreen) * 0.5;
&rgbValuesOutput[y][x].rgbBlue = (rgb1->rgbBlue + rgb2->rgbBlue) * 0.5;
combine.setPixelColor(x, y, &rgbValuesOutput[y][x]);
}
renderTopPixels += renderTopImage.getScanWidth();
renderBottomPixels += renderBottomImage.getScanWidth();
}
//SAVE IMAGE
-----WRITE VERSION USING C++11 MULTITHREADING CODE
Aucun commentaire:
Enregistrer un commentaire