Manasarala 0 Newbie Poster

hi,

Below is the code that displays 2 similar images and pixel values BGR of both images.

I wanted to know , how to calculate the distance(euclidean) between selected pixels in 2 images[like (100,100),(100,101) coordinate and so on.how to go about it?how to use the values of BGR and B1G1R1 to calculate difference.Thank You

#include <cv.h>
#include<iostream>
#include <cxcore.h>
#include <highgui.h>

using namespace std;

int main(int argc, char** argv[])


    {



     int patchXPosImg1=100,patchYPosImg1=100,patchXPosImg2=100,patchYPosImg2=100;

     int patchWidth=3, patchHeight=4;

     int i,j,k,l;


     IplImage *img1 = cvLoadImage("E:/images.jpg");
     cvNamedWindow("Image1:",1);
     cvShowImage("Image1:",img1);

     IplImage *img2 = cvLoadImage("E:/images.jpg");
     cvNamedWindow("Image2:",2);
     cvShowImage("Image2:",img2);



              for(i=patchYPosImg1;i<patchYPosImg1+patchHeight;i++)
              {

                 for(j=patchXPosImg1;j<patchXPosImg1+patchWidth;j++)
                 {

                  CvScalar s;

                  s=cvGet2D(img1,i,j); // get the (i,j) pixel value

                  printf("B=%f, G=%f, R=%f\n",s.val[0],s.val[1],s.val[2]);

               }
        }

              for(k=patchYPosImg2;k<patchYPosImg2+patchHeight;k++)
              {

                 for(l=patchXPosImg2;l<patchXPosImg2+patchWidth;l++)
                 {

                  CvScalar s;

                  s=cvGet2D(img2,k,l); // get the (k,l) pixel value

                  printf("B1=%f, G1=%f, R1=%f\n",s.val[0],s.val[1],s.val[2]);


               }
             }


    cvWaitKey();

    cvDestroyWindow("Image1:");
    cvDestroyWindow("Image2:");

    cvReleaseImage(&img1);
    cvReleaseImage(&img2);

    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.