我有一组70个RGB图像(argc = 71)。我想根据这些公式更改像素值:
l1 =(R-G)^ 2 /((R-G)^ 2 +(R-B)^ 2 +(G-B)^ 2);
l2 =(R-B)^ 2 /((R-G)^ 2 +(R-B)^ 2 +(G-B)^ 2);
13 =(R-G)^ 2 /((G-B)^ 2 +(R-B)^ 2 +(G-B)^ 2);
然后存储新图像。我尝试使用c ++的代码如下,但我一直收到这个错误:
SetPixels(99556,0x7fff76450000)malloc:*对象0x10a9ce000的错误:未分配的指针*在malloc_error_break中设置断点以进行调试
任何人都可以帮我解决这个问题吗?
提前致谢!
#include <highgui.h>
#include <cv.h>
#include <sstream>
using namespace cv;
using namespace std;
int main(int agra, char** argv){
for(int k=1;k<=argc;k++){
char* imageName = argv[k];
Mat image;
image = imread(imageName,CV_LOAD_IMAGE_UNCHANGED);
uchar l1;
uchar l2;
uchar l3;
for (int i=0; i<=image.rows;i++){
for (int j=0; j<=image.cols; j++){
Vec3b intensity = image.at<Vec3b>(Point(j, i));
uchar red = intensity.val[0];
int int_red = (int) red;
uchar green = intensity.val[1];
int int_green = (int) green;
uchar blue = intensity.val[2];
int int_blue = (int) blue;
int int_l1 = pow((int_red-int_green),2)/(pow((int_red-int_green),2)+pow((int_red - int_blue),2)+pow((int_green-int_blue),2));
int int_l2 = pow((int_red-int_blue),2)/(pow((int_red-int_green),2)+pow((int_red - int_blue),2)+pow((int_green-int_blue),2));
int int_l3 = pow((int_green-int_blue),2)/(pow((int_red-int_green),2)+pow((int_red - int_blue),2)+pow((int_green-int_blue),2));
l1 = (uchar) int_l1;
l2 = (uchar) int_l2;
l3 = (uchar) int_l3;
intensity.val[0] = l1;
intensity.val[1] = l2;
intensity.val[2] = l3;
image.at<Vec3b>(j,i)= intensity;
}
}
stringstream ss;
string name = "l1l2l3image_";
string type = ".jpg";
ss<<name<<(k)<<type;
string filename = ss.str();
ss.str("");
imwrite(filename, image);
}
return 0;
}