Ask Your Question

ritaplfigueiredo's profile - activity

2016-07-29 05:12:32 -0500 received badge  Enthusiast
2016-07-26 09:28:15 -0500 commented answer How can I perform arithmetic operations with pixel

Thank you so much, it solves my main goal!!

2016-07-26 09:27:15 -0500 received badge  Supporter (source)
2016-07-26 09:27:11 -0500 received badge  Scholar (source)
2016-07-22 04:27:36 -0500 commented answer How can I perform arithmetic operations with pixel

Thanks on the notes! Still can't seem to write the modified images... Is there anything more for me to correct? I have no 'error' message but still nothing happens

2016-07-21 10:56:13 -0500 commented answer How can I perform arithmetic operations with pixel

That is only if I let default options on imread. If I load it unchanged the order will still be RGB, right?

2016-07-21 10:11:43 -0500 commented answer How can I perform arithmetic operations with pixel

Note taken on the headers (must have learnt using an old tutorial...). Regarding the question itself, I now get the written images all black, any suggestions on that? Thanks for the tips and help!

2016-07-21 10:10:30 -0500 received badge  Editor (source)
2016-07-21 09:47:55 -0500 asked a question 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[2];
                int int_red = (int) red;

                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 = rg/(rg+rb+gb);
            int int_l2 = rb/(rg+rb+gb);
            int int_l3 = 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;
    }