gray_histo 计算直方图
原形:gray_histo(Regions, Image : : : AbsoluteHisto, RelativeHisto)
功能:计算直方图
参数:Regions:区域,要计算的区域(在image上的区域)
Image :要计算的图形
AbsoluteHisto:绝对统计数量,比如灰阶值为0-255的有多少个像素点
RelativeHisto:比例,像素值0-255占整个图像的比例
代码示例:
*显示直方图
while (true)
read_image(Image, 'D:\\2.PNG')
rgb1_to_gray (Image, GrayImage)
dev_display (GrayImage)
wait_seconds (1)
* 产生一个矩形
gen_rectangle1 (Rectangle, 0, 0, 9, 9)
dev_inspect_ctrl (AbsoluteHisto)
dev_inspect_ctrl (AbsoluteHisto)
dev_close_inspect_ctrl (AbsoluteHisto)
*1\显示原图直方图
gray_histo (Rectangle, GrayImage,AbsoluteHisto, RelativeHisto)
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
dev_set_color ('green')
gen_region_histo (Region, AbsoluteHisto, 255, 255, 1)
dev_display (Region)
dev_close_inspect_ctrl (AbsoluteHisto)
dev_inspect_ctrl (AbsoluteHisto)
dev_close_inspect_ctrl (RelativeHisto)
dev_inspect_ctrl (RelativeHisto)
*2\直方图均衡化后显示直方图
dev_close_inspect_ctrl (AbsoluteHisto)
dev_inspect_ctrl (AbsoluteHisto)
dev_close_inspect_ctrl (AbsoluteHisto)
equ_histo_image (GrayImage, ImageEquHisto)
gray_histo (ImageEquHisto, ImageEquHisto,AbsoluteHisto, RelativeHisto)
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
dev_set_color ('red')
gen_region_histo (Region, AbsoluteHisto, 255, 255, 1)
dev_display (Region)
break
endwhile
上图是给了一张全黑的图片,然后截取10*10的左上角,进行直方图计算;可以看到AbsoluteHisto下标0有100个,其他都是0
RelativeHisto下标0占比1 ,也就是100% , 其他都是0 , 因为一张全黑的图像素点的值都是0