Open main menu

CDOT Wiki β

Changes

GPU621/Group 3

2,237 bytes removed, 18:11, 9 April 2023
m
Optimizing Image Processing using Intel's Data Analytics Library for Parallel computing and Vectorization
In order to be able to more easily engage with image files, we will be utilizing the OpenCV library, leaning especially on the Mat class therein. The Mat class allows us to access the image as a n-dimensional array. Furthermore with our implementation we are able to rely on our parellelization choices instead of that built in to the OpenCV library.
 
'''OpenMP Implementation'''
 
OpenMP provides extremely simple implementation, especially the process which we are using in our code. In this process we were able to simply use a ''#pragma parallel for'' declaration for the OpenMP API to parallelize the process. With this we saw at the operations being performed at a quarter of the time it took the serial version of these processes.
 
 
<syntaxhighlight lang="cpp">
void openMP_imgProcessor::sharpenImg(cv::Mat& image) {
//supressing OpenCV messages
std::streambuf* coutbuf = std::cout.rdbuf();
std::cout.rdbuf(nullptr);
//
// Convert the image to grayscale
cv::Mat grayscale;
cv::cvtColor(image, grayscale, cv::COLOR_BGR2GRAY);
//
// Apply the kernel to the grayscale image
//finds areas with quick jumps from dark to light, increases contrast there
#pragma omp parallel for
for (int x = 1; x < image.cols - 1; x++) {
for (int y = 1; y < image.rows - 1; y++) {
double sum = 0.0;
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
sum += grayscale.at<uchar>(y + j, x + i) * LapKernel_[i + 1][j + 1];
}
}
for (int c = 0; c < 3; c++) {
image.at<cv::Vec3b>(y, x)[c] = cv::saturate_cast<uchar>(image.at<cv::Vec3b>(y, x)[c] + sum * 0.99);
}
}
}
//
//stop supressing
std::cout.rdbuf(coutbuf);
}
</syntaxhighlight lang="cpp">
 
<syntaxhighlight lang="cpp">
void openMP_imgProcessor::brightenImg(cv::Mat& image, int brightnessLvl) {
//supressing OpenCV messages
std::streambuf* coutbuf = std::cout.rdbuf();
std::cout.rdbuf(nullptr);
int width = image.cols;
int height = image.rows;
int channels = image.channels();
#pragma omp parallel for
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
for (int c = 0; c < channels; c++) {
uchar& pixel = image.at<cv::Vec3b>(row, col)[c];
pixel = cv::saturate_cast<uchar>(pixel + brightnessLvl);
}
}
}
 
//stop supressing
std::cout.rdbuf(coutbuf);
}
</syntaxhighlight lang="cpp">
72
edits