IT TIP

색상의 유사성을 확인하는 알고리즘

itqueen 2020. 10. 19. 13:45
반응형

색상의 유사성을 확인하는 알고리즘


두 RGB 색상을 비교하고 유사성 값을 생성하는 알고리즘을 찾고 있습니다 (유사성은 "평균 인간 지각과 유사 함"을 의미 함).

어떤 아이디어?

편집 :

더 이상 대답 할 수 없기 때문에 질문에 대한 편집으로 내 "솔루션"을 사용하기로 결정했습니다.

저는 제 앱에서 트루 컬러의 (매우) 작은 부분 집합을 사용하기로 결정했습니다. 그래서 제가 직접 색상 비교를 처리 할 수 ​​있습니다. 저는 약 30 가지 색상으로 작업하고 그 사이에 하드 코딩 된 거리를 사용합니다.

iPhone 앱이기 때문에 저는 objective-C로 작업했으며 구현은 색상 사이의 거리를 보여주는 아래 표를 나타내는 매트릭스입니다.

여기에 이미지 설명 입력


유클리드 공간에서 RGB 거리는 "인간의 지각과 유사"하지 않습니다.

YUV 색상 공간을 사용할 수 있으며 다음 요소를 고려합니다.

여기에 이미지 설명 입력

이 목적으로 CIE 색 공간을 사용할 수도 있습니다 .

편집하다:

YUV 색 공간은 간단한 공식을 통해 계산할 수있는 저렴한 근사치입니다. 그러나 그것은 지각 적으로 균일하지 않습니다. 지각 적으로 균일하다는 것은 색상 값에서 동일한 양의 변화가 거의 동일한 시각적 중요성의 변화를 생성해야 함을 의미합니다. 더 정확하고 엄격한 메트릭이 필요한 경우 CIELAB 색 공간 또는 다른 지각 적으로 균일 한 공간 (변환을위한 간단한 공식이없는 경우에도)을 반드시 고려해야합니다.


CIE94 (DeltaE-1994)를 사용하는 것이 좋습니다 . 인간의 색상 인식을 제대로 표현한다고합니다. 나는 내 컴퓨터 비전 관련 응용 프로그램에서 꽤 많이 사용했으며 결과에 다소 만족합니다.

그러나 이러한 비교를 수행하는 것은 계산 비용이 많이 듭니다.

  1. RGB to XYZ 두 색상 모두
  2. XYZ to LAB 두 색상 모두
  3. Diff = DeltaE94(LABColor1,LABColor2)

공식 (의사 코드) :


인간의 지각은 강도보다 채도가 약합니다.

For example, in commercial video, the YCbCr/YPbPr color spaces (also called Y'UV) reduces the resolution of the chroma info but preserves the luma (Y). In digital video compression such as 4:2:0 and 4:2:2 reduces the chroma bitrate due to relatively weaker perception.

I believe that you can calculate a distance function giving higher priority over luma (Y) and less priority over chroma.

Also, under low intensity, human vision is practically black-and-white. Therefore, the priority function is non-linear in that for low luma (Y) you put less and less weight on chroma.

More scientific formulas: http://en.wikipedia.org/wiki/Color_difference


There's an excellent write up on the subject of colour distances here: http://www.compuphase.com/cmetric.htm

In case that resource disappears the author's conclusion is that the best low-cost approximation to the distance between two RGB colours can be achieved using this formula (in code).

typedef struct {
   unsigned char r, g, b;
} RGB;

double ColourDistance(RGB e1, RGB e2)
{
  long rmean = ( (long)e1.r + (long)e2.r ) / 2;
  long r = (long)e1.r - (long)e2.r;
  long g = (long)e1.g - (long)e2.g;
  long b = (long)e1.b - (long)e2.b;
  return sqrt((((512+rmean)*r*r)>>8) + 4*g*g + (((767-rmean)*b*b)>>8));
}

Color perception is not Euclidean. Any distance formula will be both good enough and terrible at the same time. Any measure based on Euclidean distance (RGB, HSV, Luv, Lab, ...) will be good enough for similar colors, showing aqua being close to teal. But for non-close values it gets to be arbitrary. For instance, is red closer to green or to blue?

From Charles Poynton's Color FAQ:

The XYZ and RGB systems are far from exhibiting perceptual uniformity. Finding a transformation of XYZ into a reasonably perceptually-uniform space consumed a decade or more at the CIE and in the end no single system could be agreed.


RGB 큐브의 색상 유사성은 유클리드 거리 (피타고라스 공식 사용)로 측정됩니다.

편집 : 다시 생각하면 이것은 대부분의 다른 색상 공간에서도 마찬가지입니다.

참고 URL : https://stackoverflow.com/questions/5392061/algorithm-to-check-similarity-of-colors

반응형