how to get distance in RGB space

how to get distance in RGB space

Hello,

I want to calculate the Euclidean distance in RGB space for the pixels of a source and a reference image. This is what I think will work (pseudo code):
src = source image (RGB)
ref = reference image (RGB)
dst = dest image (GREY)
tmp = temporary image (RGB)

AbsDiff(src, ref, tmp) //dest=|src-ref|
Sqr(tmp); //tmp=tmp*tmp
ColorToGrey(tmp, dst) //dest=tmp_r + tmp_g + tmp_b
Sqrt(dst)

the problem is that src is in 8u format and sqr will get out of range so I have to convert to float32 and back again. I thought about using AddSquare as it can convert to float32 and square together but this requires to zero the accumulation buffer first.

Is there a better solution?

Thanks

Markus

3 posts / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.

Hi,

There is special function set in ippIP ippiSqrDist. Also there may be useful ippiImageQualityIndex function. Ifyou need absolutely the same formulae asyou had mentioned, it is useful to do calculations not for all image at once, but row by row with a buffer of row-length. It will be significantly faster.

Regards,

I don't see how ippiSqrDist can help me. As far as I understand it they compare regions - one from a source image and one from a template. These functions sum up the pixel distances what is not desired. I need:

s: source image
r: reference image
d: destination

d(x,y)= sqrt ( (s(x,y).r- r(x,y).r) +
(s(x,y).g- r(x,y).g) +
(s(x,y).b- r(x,y).b) )

If the range of dest could hold the squared values then sqrt is not neccessary.

Edit: Thought about it after having a coffee. I can set the template to zero and to 1x1 size so I get the desired effect. I'll give it a try.

Edit2: Had another cup of coffee. Unfortunately (at least for me) ippiSqrDist return normalized SSD values. I don't see what happens when either the template or the image region is filled with zero. If the formula in the manual is used this should result in a division by zero when the values are normalized.

Message Edited by muhkuh on 01-18-2005 08:50 AM