This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* version 2.4 of openCV */ | |
using namespace cv; | |
/** | |
* Takes in a RGB image and outputs | |
* a Lab space image. | |
**/ | |
Mat BGR2LAB(Mat const &imgRGB){ | |
Mat imgLab; | |
cvtColor(imgRGB, imgLab, CV_RGB2Lab); | |
return imgLab; | |
} | |
/** | |
* Takes in image in the LAB space and splits | |
* out the a* stream. Returning it as a matrix, | |
* to be saved out to file or manipulated | |
**/ | |
Mat alphaLAB(Mat const &imgLab){ | |
Mat alphaLab; | |
cvtColor(imgLab, alphaLab, CV_Lab2RGB); | |
Size s = alphaLab.size(); | |
int steps = imgLab.step; | |
int channels = imgLab.channels(); | |
for(int y = 0; y < s.height; y++){ | |
for(int x = 0; x < s.width; x++){ | |
(*alphaLab.ptr<Point3_<uchar> >(y,x)).x = imgLab.data[steps*y + channels * x + 1]; | |
(*alphaLab.ptr<Point3_<uchar> >(y,x)).y = imgLab.data[steps*y + channels * x + 1]; | |
(*alphaLab.ptr<Point3_<uchar> >(y,x)).z = imgLab.data[steps*y + channels * x + 1]; | |
} | |
} | |
return alphaLab; | |
} | |
/** | |
* Takes in image in the LAB space and splits | |
* out the b* stream. Returning it as a matrix, | |
* to be saved out to file or manipulated | |
**/ | |
Mat betaLAB(Mat &imgLab){ | |
Mat betaLab; | |
cvtColor(imgLab, betaLab, CV_Lab2RGB); | |
Size s = betaLab.size(); | |
int steps = imgLab.step; | |
int channels = imgLab.channels(); | |
for(int y = 0; y < s.height; y++){ | |
for(int x = 0; x < s.width; x++){ | |
(*betaLab.ptr<Point3_<uchar> >(y,x)).x = imgLab.data[steps*y + channels * x + 2]; | |
(*betaLab.ptr<Point3_<uchar> >(y,x)).y = imgLab.data[steps*y + channels * x + 2]; | |
(*betaLab.ptr<Point3_<uchar> >(y,x)).z = imgLab.data[steps*y + channels * x + 2]; | |
} | |
} | |
return betaLab; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment