天天看点

Halcon怎么处理32位的真彩色图?

原图需要先分割下通道(RGBA)再合成(RGB),针对RGB进行处理。

* 读图像
read_image (Image, 'D:/autocad.png')
 
* 获取图像宽高
get_image_size (Image, Width, Height)
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_display (Image)
 
* 彩色转灰度图
count_channels (Image, Channels)
if (Channels == 3)
    rgb1_to_gray (Image, Image)
endif
 
* 真彩色转灰度图
if (Channels == 4)
    decompose4 (Image, ImageR, ImageG, ImageB, ImageA)
    compose3 (ImageR, ImageG, ImageB, MultiChannelImage)
    rgb1_to_gray (MultiChannelImage, Image)
endif

      

继续阅读