Search code examples
matlabimage-processingcolorsrgbhsv

Average of pixels in HSV vs RGB colorspace


My question is a bit more conceptual than anything. I am representing a spatial map (map of a metropolitan area, say) in a polar coordinate system. I have recorded data from people in a 10x10 home suburban neighbourhood asking where they would like to live in this metropolitan area given by (r,theta) -- r the distance from the center, theta the angle around the x axis, so I am using a polar coordinate system and using HSV to color code it, keeping V=1=constant. After getting the HSV color of each home, I transformed this 10x10x3 HSV matrix to RGB and used image() to display the following plot.

Fig1: [10x10 grid representing a neighbourhood. Colours represent where these families want to live in the metropolitan area. Legend shows metropolitan area in polar coords, HSV colorspace where V=1 always.]

Now, I am trying to create a better visual representation of this suburban neighbourhood to see if people are grouped according to their preference of where they would like to live in the metropolitan area. Using

Img2=imresize(Img,1000,'bilinear','colormap','original');

This increases the size of the 10x10x3 RGB matrix to 10000x10000x3 RGB matrix while using a bilinear interpolation between pixels, thus sort of smoothing out the picture shown here:

Fig2: [Big smoothed matrix using bilinear interpolating between pixels]

My question is: Is it valid to use this interpolation method in RGB space, if my main interests lie in HSV space i.e. the polar coordinate metropolitan area? In other words, when this function takes the average colour of many pixels in RGB, will it represent the correct radius, and angle in the metropolitan area?

Thank you so much ahead of time. I apologize for the long winded build up to a potentially simple question.


Solution

  • V is defined as the max (R,G,B).

    If you interpolate from RGB(255,0,0) to RGB(0,0,255), then halfway you will end up with RGB(128,0,128).

    You see the max is then 128. So you cannot use rgb interpolation, unless you increase the V back to 1 (or 255, if you use 8 bit)

    btw. I would not interpolate, as you cannot assume the underlying values are linear.

    See here for more info: https://stackoverflow.com/a/2594030/461499