设置首页收藏本站
开启左侧

[文档] halcon中的RGB到任意颜色空间转换

[复制链接]
绝地武士 发表于 2023-7-12 18:30:33 | 显示全部楼层 |阅读模式
trans_from_rgb 转换图像RGB到任意颜色空间
  1. trans_from_rgb(ImageRed, ImageGreen, ImageBlue : ImageResult1, ImageResult2, ImageResult3 : ColorSpace : )
复制代码

支持图像类型:byte, uint2, int4, real(real类型下图像值只能是0和1,否则结果不可预料)

颜色空间:
'yiq'
微信截图_20230712175928.png
取值范围:
微信截图_20230712180233.png

'yuv'
微信截图_20230712180404.png
取值范围:
微信截图_20230712180412.png

'argyb'
微信截图_20230712180500.png
取值范围:
微信截图_20230712180504.png

'ciexyz'
微信截图_20230712180542.png
所使用的原色sRGB分别对应于CIE Rec. 709以及用作白点D65。
使用的原色(x,y,z):
微信截图_20230712180641.png
取值范围:
微信截图_20230712180647.png

'hls'
  1. Min := min([R, G, B])
  2.   Max := max([R, G, B])
  3.   L := (Min + Max) / 2
  4.   if (Max == Min)
  5.      H := 0
  6.      S := 0
  7.   else
  8.      if (L > 0.5)
  9.         S := (Max - Min) / (2 - Max - Min)
  10.      else
  11.         S := (Max - Min) / (Max + Min)
  12.      endif
  13.      if (R == Max)
  14.         H := ((G - B) / (Max - Min)) * rad(60)
  15.      elseif (G == Max)
  16.         H := (2 + (B - R) / (Max - Min)) * rad(60)
  17.      elseif (B == Max)
  18.         H := (4 + (R - G) / (Max - Min)) * rad(60)
  19.      endif
  20.   endif
复制代码

取值范围:
微信截图_20230712181926.png

'hsi'
微信截图_20230712182015.png
取值范围:
微信截图_20230712182114.png

'hsv'
  1. Min := min([R, G, B])
  2.   Max := max([R, G, B])
  3.   V := Max
  4.   if (Max == Min)
  5.      S := 0
  6.      H := 0
  7.   else
  8.      S := (Max - Min) / Max
  9.      if (R == Max)
  10.         H := ((G - B) / (Max - Min)) * rad(60)
  11.      elseif (G == Max)
  12.         H := (2 + (B - R) / (Max - Min)) * rad(60)
  13.      elseif (B == Max)
  14.         H := (4 + (R - G) / (Max - Min)) * rad(60)
  15.      endif
  16.   endif
复制代码

取值范围:
微信截图_20230712182209.png

'ihs'
  1. Min := min([R, G, B])
  2.    Max := max([R, G, B])
  3.    I := (R + G + B) / 3
  4.    if (I == 0)
  5.       H := 0
  6.       S := 1
  7.    else
  8.       S := 1 - Min / I
  9.       if (S == 0)
  10.            H := 0
  11.       else
  12.          X := (R + R - G - B) / 2
  13.          Y := (R - G) * (R - G) + (R - B) * (G - B)
  14.          Z := sqrt(Y)
  15.          if (Z == 0)
  16.             H := 0
  17.          else
  18.             H := acos(X / Z)
  19.          endif
  20.          if (B > G)
  21.             H := rad(360) - H
  22.          endif
  23.       endif
  24.    endif
复制代码

取值范围:
微信截图_20230712182346.png

'cielab'
微信截图_20230712182425.png
其中
  1. f(t) = t^(1/3),           t > (24/116)^3
  2.      f(t) = (841/108)*t + 16/116,  otherwise.

  3.      Black point B: (Rb, Gb, Bb) = (0, 0, 0)
  4.      White point W = (Rw, Gw, Bw), according to image type:
  5.        byte:=(255, 255, 255), uint2:=(2^16-1, 2^16-1, 2^16-1),
  6.        int4:=(2^31-1, 2^31-1, 2^31-1), real:=(1.0, 1.0, 1.0)
复制代码

取值范围:
微信截图_20230712182539.png

'cielchab'
微信截图_20230712182632.png
其中
  1. f(t) = t^(1/3),           t > (24/116)^3
  2.      f(t) = (841/108)*t + 16/116,  otherwise.

  3.      h_ab lies between 0° and 90° if a and b are both positive,
  4.      between 90° and 180° if a is negative and b is positive,
  5.      between 180° and 270° if a and b are both negative, and
  6.      between 270° and 360° if a is positive and b is negative.

  7.      Black point B: (Rb, Gb, Bb) = (0, 0, 0)
  8.      White point W = (Rw, Gw, Bw), according to image type:
  9.        byte:=(255, 255, 255), uint2:=(2^16-1, 2^16-1, 2^16-1),
  10.        int4:=(2^31-1, 2^31-1, 2^31-1), real:=(1.0, 1.0, 1.0)
复制代码

取值范围:
微信截图_20230712182715.png

'cieluv'
微信截图_20230712182925.png
其中
  1. f(t) = t^(1/3),           t > (24/116)^3
  2.      f(t) = (841/108)*t + 16/116,  otherwise.

  3.      Black point B: (Rb, Gb, Bb) = (0, 0, 0)
  4.      White point W = (Rw, Gw, Bw), according to image type:
  5.        byte:=(255, 255, 255), uint2:=(2^16-1, 2^16-1, 2^16-1),
  6.        int4:=(2^31-1, 2^31-1, 2^31-1), real:=(1.0, 1.0, 1.0)
复制代码

取值范围:
微信截图_20230712183000.png

'cielchuv'
微信截图_20230712183153.png
其中
  1. f(t) = t^(1/3),           t > (24/116)^3
  2.      f(t) = (841/108)*t + 16/116,  otherwise.

  3.      h_uv lies between 0° and 90° if u and v are both positive,
  4.      between 90° and 180° if u is negative and v is positive,
  5.      between 180° and 270° if u and v are both negative, and
  6.      between 270° and 360° if u is positive and v is negative.

  7.      Black point B: (Rb, Gb, Bb) = (0, 0, 0)
  8.      White point W = (Rw, Gw, Bw), according to image type:
  9.        byte:=(255, 255, 255), uint2:=(2^16-1, 2^16-1, 2^16-1),
  10.        int4:=(2^31-1, 2^31-1, 2^31-1), real:=(1.0, 1.0, 1.0)
复制代码

取值范围:
微信截图_20230712183222.png

'i1i2i3'
微信截图_20230712183257.png
取值范围:
微信截图_20230712183306.png

'ciexyz2'
微信截图_20230712183402.png
取值范围:
微信截图_20230712183409.png

'ciexyz3'
微信截图_20230712183454.png
取值范围:
微信截图_20230712183500.png

'ciexyz4'
微信截图_20230712183546.png
使用的原色(x, y, z)
微信截图_20230712183554.png
取值范围:
微信截图_20230712183705.png

'lms'
微信截图_20230712183833.png
从概念上讲,这是从RGB到CIEXYZ的转换(见上面的"CIEXYZ"),然后是从CIEXYZ到LMS的转换。
取值范围:
微信截图_20230712183920.png

参考例子:
  1. read_image(Image,'patras')
  2. dev_display(Image)
  3. decompose3(Image, Image1, Image2, Image3)
  4. trans_from_rgb(Image1,Image2,Image3,ImageH,ImageS,ImageV,'hsv')
  5. trans_to_rgb(ImageH,ImageS,ImageV,ImageR,ImageG,ImageB,'hsv')
  6. compose3(ImageR,ImageG,ImageB,Multichannel)
  7. dev_display(Multichannel)
复制代码
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
Ggg3434 发表于 2023-7-13 09:29:12 | 显示全部楼层
学习一下
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
老老常 发表于 2023-7-13 15:23:58 | 显示全部楼层
牛皮牛皮,学习了。它那个不同颜色的转换系数是怎么来的?
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
shimi20 发表于 2023-7-19 17:38:27 | 显示全部楼层
谢谢分享,刚刚开始学习,虽然还看不懂,感觉很厉害的样子,先收藏了
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
qqdewomen 发表于 2023-7-23 10:56:32 | 显示全部楼层
感谢大佬,学习学习
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
Mbot 发表于 2023-8-1 16:24:22 | 显示全部楼层
牛皮牛皮,学习了。
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
诸葛释冰 发表于 2023-8-21 14:21:53 | 显示全部楼层
谢谢分享,刚刚开始学习,虽然还看不懂,感觉很厉害的样子,先收藏了
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
livehu5188 发表于 2023-10-5 22:45:07 | 显示全部楼层
刚学 还是有点看不懂
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
freekun139com 发表于 2023-10-8 09:48:12 | 显示全部楼层
学习一下,测试了大半天终于差不多搞明白了,感谢楼主分享
RGB到HSV转换测试.png
RGB到HSV转换测试.hdev (3.15 KB, 下载次数: 1)
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
李li 发表于 2023-10-16 07:47:19 | 显示全部楼层
谢谢分享,虽然还看不懂,先收藏了
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表