图像YCbCr与RGB空间相互转换:
- dev_update_off()
- dev_set_draw('margin')
- Path := 'C:/WITIAIIDE/ProgramsSamples/testimages'
- ImageFormat := 'jpg'
- list_image_files(Path, ImageFormat, [], ImageFiles)
- ImagePath2 := ImageFiles[2]
- read_image(Image1, ImagePath2)
- count_channels(Image1, Channels1)
- dev_disp_text(Channels1, 'window', 30, 'left', 'black', [], [])
- decompose3(Image1, R, G, B)
- convert_image_type(R, R1, 'real')
- convert_image_type(G, G1, 'real')
- convert_image_type(B, B1, 'real')
- gen_empty_obj(R2)
- scale_image(R1, R2, 65.481, 0)
- scale_image(G1, G2, 128.553, 0)
- scale_image(B1, B2, 24.966, 0)
- add_image(R2, G2, Y, 1.0, 0)
- add_image(Y, B2, Y, 1.0, 16)
- scale_image(R1, R21, -37.797, 0)
- scale_image(G1, G21, -74.203, 0)
- scale_image(B1, B21, 112, 0)
- add_image(R21, G21, Cb, 1.0, 0)
- add_image(Cb, B21, Cb, 1.0, 128)
- scale_image(R1, R22, 112, 0)
- scale_image(G1, G22, -93.786, 0)
- scale_image(B1, B22, -18.214, 0)
- add_image(R22, G22, Cr, 1.0, 0)
- add_image(Cr, B22, Cr, 1.0, 128)
- compose3(Y, Cb, Cr, MultiChannelImage)
- dev_display(MultiChannelImage)
- * 从YCbCr转换到RGB
- scale_image(Y, Y1, 0.0046, 0)
- scale_image(Cb, Cb1, 0, 0)
- scale_image(Cr, Cr1, 0.0063, 0)
- add_image(Y1, Cr1, ImageRed, 1.0, 0)
- add_image(ImageRed, Cb1, ImageRed, 1.0, 0.8742)
- scale_image(Y, Y2, 0.0046, 0)
- scale_image(Cb, Cb2, -0.0015, 0)
- scale_image(Cr, Cr2, -0.0032, 0)
- add_image(Y2, Cr2, ImageGreen, 1.0, 0)
- add_image(ImageGreen, Cb2, ImageGreen, 1.0, -0.5317)
- scale_image(Y, Y3, 0.0046, 0)
- scale_image(Cb, Cb3, 0.0079, 0)
- scale_image(Cr, Cr3, 0, 0)
- add_image(Y3, Cr3, ImageBlue, 1.0, 0)
- add_image(ImageBlue, Cb3, ImageBlue, 1.0, 1.0856)
- compose3(ImageRed, ImageGreen, ImageBlue, MultiChannelImage1)
- dev_display(MultiChannelImage1)
复制代码
参考:【1】图像颜色空间工具箱
|