Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How can I perform arithmetic operations with pixel

I have a set of 70 RGB images (argc=71). I wanted to change pixel values according to these formulas:

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);

l3 = (R-G)^2/((G-B)^2 + (R-B)^2 + (G-B)^2);

And then store the new images. The code I tried using c++ is below but I keep getting this error:

SetPixels(99556,0x7fff76450000) malloc: * error for object 0x10a9ce000: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug

Can anyone help me solve this matter?

Thanks in advance!

#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;
    }

How can I perform arithmetic operations with pixel

I have a set of 70 RGB images (argc=71). I wanted to change pixel values according to these formulas:

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);

l3 = (R-G)^2/((G-B)^2 + (R-B)^2 + (G-B)^2);

And then store the new images. The code I tried using c++ is below but I keep getting this error:

SetPixels(99556,0x7fff76450000) malloc: * error for object 0x10a9ce000: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug

Can anyone help me solve this matter?

Thanks in advance!

#include <highgui.h>
<opencv2/highgui.hpp>
#include <cv.h>
<opencv2/opencv.hpp>
#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));
image.at<Vec3b>(Point(i, j));
                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)= image.at<Vec3b>(i,j)= intensity;

            }
        }

        stringstream ss;
        string name = "l1l2l3image_";
        string type = ".jpg";
        ss<<name<<(k)<<type;
        string filename = ss.str();
        ss.str("");
        imwrite(filename, image);
    }
    return 0;
    }

How can I perform arithmetic operations with pixel

I have a set of 70 RGB images (argc=71). I wanted to change pixel values according to these formulas:

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);

l3 = (R-G)^2/((G-B)^2 + (R-B)^2 + (G-B)^2);

And then store the new images. The code I tried using c++ is below but I keep getting this error:

SetPixels(99556,0x7fff76450000) malloc: * error for object 0x10a9ce000: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug

Can anyone help me solve this matter?

Thanks in advance!

#include <opencv2/highgui.hpp>
#include <opencv2/opencv.hpp>
#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(i, j));
                uchar blue = intensity.val[0];
                int int_blue = (int) blue;
                uchar green = intensity.val[1];
                int int_green = (int) green;
                uchar red = intensity.val[0];
intensity.val[2];
                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 rg = pow(int_red-int_green,2);
            int rb = pow(int_red-int_blue,2);
            int gb = pow(int_green - int_blue,2);

            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));
    rg/(rg+rb+gb);
            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));
    rb/(rg+rb+gb);
            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));
gb/(rg+rb+gb);

                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>(i,j)= intensity;

            }
        }

        stringstream ss;
        string name = "l1l2l3image_";
        string type = ".jpg";
        ss<<name<<(k)<<type;
        string filename = ss.str();
        ss.str("");
        imwrite(filename, image);
    }
    return 0;
    }