Reputation: 437
here is a function where I try to improve the image colors. It works but it is really slow...Maybe someone has a better idea?
static Mat correctColor(Mat AImage) {
Mat copyImage;
AImage.copyTo(copyImage);
Mat imgLab;
cvtColor(copyImage, imgLab, CV_BGR2Lab);
for (int y = 0; y < imgLab.rows; y++) {
for (int x = 0; x < imgLab.cols; x++) {
//get pixel value
imgLab.ptr<uchar > (y)[x * 3] = imgLab.ptr<uchar > (y)[x * 3]*0.3;
}
}
cvtColor(imgLab, copyImage, CV_Lab2BGR);
Mat img(copyImage.rows, copyImage.cols, CV_32FC3);
copyImage.convertTo(img, CV_32FC3, 1 / 255.);
blur(img, img, Size(255, 255));
Mat img32(copyImage.rows, copyImage.cols, CV_32FC3);
copyImage.convertTo(img32, CV_32FC3, 1 / 255.);
img.mul(img, 2);
divide(img32, img, img);
img.convertTo(copyImage, CV_8U, 255.0);
return copyImage;
}
Upvotes: 2
Views: 2902
Reputation: 23
Apart from the optimizations to the programs. You can add compiler optimization flags like -o3
and -NDEBUG
, while compiling.
Upvotes: -2
Reputation: 20058
The best way to optimize is to start where you spend the most time. So, I strongly recommend you to profile this code to know exactly which parts of your code are the most time-consuming.
Now, some general ideas on how to improve:
Upvotes: 2
Reputation: 93410
The major problem is that you are creating several copies of the original image in memory: AImage, copyImage, imgLab, img, img32.
First optimization should be what @Eric suggested (pass by reference):
static Mat correctColor(Mat& AImage) {
As for the rest of your code, see if you can decrease the number of copies you work with.
OpenCV has a GPU module which implements several functions in the GPU, including cv::blur()
. This implementation is based on the CUDA framework, so if your graphics card is NVIDIA you are in luck: gpu::blur()
.
Upvotes: 2
Reputation: 2223
Improve image colors? You should try Histogram Equalization instead. Look for the equalizeHist() function.
Upvotes: 0
Reputation: 2341
First of all, you should pass your argument by reference since you already create a clone in your code.
Upvotes: 1