#include "normal.h"
extern char pic_name[20];
extern double mccLabModel[24][3];
extern Mat src;
extern Mat imageROI, mccROI[24];
extern int ccm_rect[24][4];
extern double mccLab[24][3], Eab[24], Eab_sum, Eab_max, Sat, Cab[24], Cab_sum, Cab_max;
/**********************************************
*********将24个中心色块取出到mccROI中**********
**********************************************/
void mccRoiGet(Mat mat1){
char str[10];
int i=0, j=0;
for(i=0; i<4; i++){
for(j=0; j<6; j++){
mccROI[j+i*6] = mat1(cv::Rect(ccm_rect[j+6*i][0], ccm_rect[j+6*i][1],
ccm_rect[j+6*i][2] - ccm_rect[j+6*i][0], ccm_rect[j+6*i][3] - ccm_rect[j+6*i][1]));
}
}
}
/**********************************************
*********获取24色块中分别取出中心小色块********
**********************************************/
void mccRectAddr(Mat mat1, Mat mat2, int* rectAddr){
int i, j;
for(j=0; j<4; j++){
for(i=0; i<6; i++){
ccm_rect[i+6*j][0] = rectAddr[0] + (rectAddr[2] - rectAddr[0]) * (12 + 6*i + 34 * i )/ 234;
ccm_rect[i+6*j][1] = rectAddr[1] + (rectAddr[3] - rectAddr[1]) * (10 + 6*j + 34 * j) / 151;
ccm_rect[i+6*j][2] = rectAddr[0] + (rectAddr[2] - rectAddr[0]) * (22 + 6*i + 34 * i)/ 234;
ccm_rect[i+6*j][3] = rectAddr[1] + (rectAddr[3] - rectAddr[1]) * (20 + 6*j + 34 * j) / 151;
rectangle(mat1, Point(ccm_rect[i+6*j][0], ccm_rect[i+6*j][1]), Point(ccm_rect[i+6*j][2], ccm_rect[i+6*j][3]), Scalar(255,0,0), 2);
}
}
mccRoiGet(mat2);
}
/*************************************************
**************计算Eab*****************************
*************************************************/
void mccEab(){
IplImage pI_1;
CvScalar s;
int width, height;
int i, j, k;
Eab_sum = 0;
Eab_max = 0;
for(k=0; k< 18; k++){
pI_1 = mccROI[k];
cvCvtColor(&pI_1, &pI_1, CV_BGR2Lab);
width = mccROI[k].rows;
height = mccROI[k].cols;
for(i=0; i<width; i++){
for(j=0; j< height; j++){
s = cvGet2D(&pI_1, i, j);
if(i==0 && j==0){
mccLab[k][0] = s.val[0];
mccLab[k][1] = s.val[1];
mccLab[k][2] = s.val[2];
}else{
mccLab[k][0] = (s.val[0] + mccLab[k][0]) / 2;
mccLab[k][1] = (s.val[1] + mccLab[k][1]) / 2;
mccLab[k][2] = (s.val[2] + mccLab[k][2]) / 2;
}
}
}
mccLab[k][0] = mccLab[k][0] * 100 / 255;
mccLab[k][1] = mccLab[k][1] - 128;
mccLab[k][2] = mccLab[k][2] - 128;
Eab[k] = (mccLab[k][0] - mccLabModel[k][0]) * (mccLab[k][0] - mccLabModel[k][0]) + \
(mccLab[k][1] - mccLabModel[k][1]) * (mccLab[k][1] - mccLabModel[k][1]) + \
(mccLab[k][2] - mccLabModel[k][2]) * (mccLab[k][2] - mccLabModel[k][2]);
Eab[k] = sqrt(Eab[k]);
if(Eab_sum==0){
Eab_sum = Eab[k];
}else{
Eab_sum = (Eab[k] + Eab_sum) / 2;
}
if(Eab_max < Eab[k]){
Eab_max = Eab[k];
}
printf("mccLab[%d]->Eab:%lf\n", k, Eab[k]);
cvCvtColor(&pI_1, &pI_1, CV_Lab2BGR);
}
printf("Eab_sum:%lf\n", Eab_sum);
}
void mccSat(){
IplImage pI_1;
CvScalar s;
int width, height;
int i, j, k;
double ab_meas=0, ab_idea=0;
for(k=0; k< 18; k++){
pI_1 = mccROI[k];
cvCvtColor(&pI_1, &pI_1, CV_BGR2Lab);
width = mccROI[k].rows;
height = mccROI[k].cols;
for(i=0; i<width; i++){
for(j=0; j< height; j++){
s = cvGet2D(&pI_1, i, j);
if(i==0 && j==0){
mccLab[k][0] = s.val[0];
mccLab[k][1] = s.val[1];
mccLab[k][2] = s.val[2];
}else{
mccLab[k][0] = (s.val[0] + mccLab[k][0]) / 2;
mccLab[k][1] = (s.val[1] + mccLab[k][1]) / 2;
mccLab[k][2] = (s.val[2] + mccLab[k][2]) / 2;
}
}
}
mccLab[k][0] = mccLab[k][0] * 100 / 255;
mccLab[k][1] = mccLab[k][1] - 128;
mccLab[k][2] = mccLab[k][2] - 128;
ab_meas = sqrt((mccLab[k][1] * mccLab[k][1])+(mccLab[k][2] * mccLab[k][2])) + ab_meas;
ab_idea = sqrt((mccLabModel[k][1] * mccLabModel[k][1])+(mccLabModel[k][2] * mccLabModel[k][2])) + ab_idea;
cvCvtColor(&pI_1, &pI_1, CV_Lab2BGR);
}
ab_meas = ab_meas / 18;
ab_idea = ab_idea / 18;
Sat = ab_meas / ab_idea;
printf("Sat:%lf\n", Sat);
}
void mccCab(){
IplImage pI_1;
CvScalar s;
int width, height;
int i, j, k;
double a_err=0, b_err=0;
Cab_sum = 0;
Cab_max = 0;
for(k=0; k< 18; k++){
pI_1 = mccROI[k];
cvCvtColor(&pI_1, &pI_1, CV_BGR2Lab);
width = mccROI[k].rows;
height = mccROI[k].cols;
for(i=0; i<width; i++){
for(j=0; j< height; j++){
s = cvGet2D(&pI_1, i, j);
if(i==0 && j==0){
mccLab[k][0] = s.val[0];
mccLab[k][1] = s.val[1];
mccLab[k][2] = s.val[2];
}else{
mccLab[k][0] = (s.val[0] + mccLab[k][0]) / 2;
mccLab[k][1] = (s.val[1] + mccLab[k][1]) / 2;
mccLab[k][2] = (s.val[2] + mccLab[k][2]) / 2;
}
}
}
mccLab[k][0] = mccLab[k][0] * 100 / 255;
mccLab[k][1] = mccLab[k][1] - 128;
mccLab[k][2] = mccLab[k][2] - 128;
a_err = mccLab[k][1] / Sat;
b_err = mccLab[k][2] / Sat;
Cab[k] = (a_err - mccLabModel[k][1]) * (a_err - mccLabModel[k][1]) + \
(b_err - mccLabModel[k][2]) * (b_err - mccLabModel[k][2]);
Cab[k] = sqrt(Cab[k]);
if(Cab_max < Cab[k]){
Cab_max = Cab[k];
}
cvCvtColor(&pI_1, &pI_1, CV_Lab2BGR);
Cab_sum = Cab_sum + Cab[k];
printf("Cab[%d]:%lf\n", k, Cab[k]);
}
Cab_sum = Cab_sum / 18;
printf("Cab_sum:%lf\n", Cab_sum);
}
- 1
- 2
前往页