本帖最后由 freekun139com 于 2023-10-8 09:32 编辑
一张622x468的图片, 使用trans_from_rgb转换到hsv耗时0.0013762
自定义函数计算每个像素点进行转换,8线程并发耗时36.6785,耗时约3W倍
想知道低层的并发是如何做到如此高效的,哪位大佬研究过指点一二,感谢
*测试函数1把RGB像素转换为HSV像素: rgb_to_hsv (R, G, B, H, S, V)
* RGB参数范围R(0~255),G(0~255),B(0~255)
* HSV定义范围H(0~360),S(0~1.0),V(0~1.0)
* HSV转换结果H(0~255),S(0~255),V(0~255)
R := R / 255.0
G := G / 255.0
B := B / 255.0
Cmax := max([R,G,B])
Cmin := min([R,G,B])
********************************************************************************
if (Cmax = Cmin)
H := 0
elseif (R = Cmax and G>=B)
H := 60 * ((G-B)/(Cmax-Cmin) + 0)
elseif (R = Cmax and G<B)
H := 60 * ((G-B)/(Cmax-Cmin) + 6)
elseif (G = Cmax)
H := 60 * ((B-R)/(Cmax-Cmin) + 2)
elseif (B = Cmax)
H := 60 * ((R-G)/(Cmax-Cmin) + 4)
endif
********************************************************************************
if (Cmax = 0)
S := 0
else
S := (Cmax-Cmin)/Cmax
endif
********************************************************************************
V := Cmax
********************************************************************************
* 转换为Byte类型
H := H / 360 * 255
S := S * 255
V := V * 255
测试函数2分行获取像素值进行转换:par_rgb_to_hsv(mageR, ImageG, ImageB, ImageH, ImageS, ImageV, Width, RowBgn, RowEnd)
for row := RowBgn to RowEnd by 1
for col := 0 to Width-1 by 1
get_grayval (ImageR, row, col, GrayvalR)
get_grayval (ImageG, row, col, GrayvalG)
get_grayval (ImageB, row, col, GrayvalB)
rgb_to_hsv (GrayvalR, GrayvalG, GrayvalB, H, S, V)
set_grayval (ImageH, row, col, H)
set_grayval (ImageS, row, col, S)
set_grayval (ImageV, row, col, V)
endfor
endfor
|