Question

I have been searching this for days but i can't seem to know where to start. I am trying to compare a base image with 10 other images by their color and i am bounded to use either euclidean or histogram matching without using opencv functions. I have only tried euclidean distance. What i want to do is get the distance of the each pixel in image1 and image2. I displayed the distances and i am getting very high values. What could be wrong here in my code? Please help. :)

for(p=0;p<height;p++) // row 
{

    for(p2=0;p2<inputHeight;p2++) // row 
    {                       
        for(u2=0;u2<inputWidth;u2++) // col 
        { 
            r2 = inputData[p2*inputStep+u2*inputChannels+2]; 
            g2 = inputData[p2*inputStep+u2*inputChannels+1]; 
            b2 = inputData[p2*inputStep+u2*inputChannels+0];     
        } 
    }                               
    for(p=0;p<height;p++) // row 
    {
        for(u=0;u<width;u++) // col 
        { 
            r = data[p*step+u*channels+2]; 
            g = data[p*step+u*channels+1]; 
            b = data[p*step+u*channels+0];     
        }
    }

    euclidean=(euclidean+sqrt(pow(b2-b,2) + pow(g2-g, 2) + pow(r2-r,2))); 
}

No correct solution

OTHER TIPS

Your program tends to get very high value as you summed all pixels' Euclidean distance together:

euclidean=(euclidean+sqrt(pow(b2-b,2) + pow(g2-g, 2) + pow(r2-r,2))); 

I suggest you to do as follows:

  1. Compute color histogram (vector features) of the images.

  2. Compute correlation coefficient between these histograms as the differences of the images.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top