Halcon - 获取分支分数
Halcon - Get a score for branches
我需要找到有很多分支的形状。但是只有 region_features 我无法完成这项工作。
基本上,我需要一个“分支因子”的分数。例如,一颗星会有相当高的分数,因为每个尖端都是一个分支。一个树枝的图片会得分高,因为它有许多较小的分支..球体或立方体得分低,因为它没有很多分支..
我试过面积和周长的比例,但是不够精确..
这里有 2 个样本.. 一个应该有高分,一个应该有低分:
这些只是解释我所说的分支的意思的示例。形状可以有任何形式。
没有,没有这个参数
也许您可以使用如下代码提取此参数:
* load image example
read_image(Image,'ppUXL.jpg')
* create 4 Regions
binary_threshold (Image, Region, 'max_separability', 'dark', UsedThreshold)
connection (Region, Regions)
count_obj (Regions,NumRegions)
NumBranches :=[]
* for every region in Regions
for i:=1 to NumRegions by 1
* select the region
select_obj (Regions, RegionSelected, i)
* --------------------------------------------------------------------------
* Here I want to calculate the region convex hull,
* i.e. the smallest region convex region that contains the selected region
* https://en.wikipedia.org/wiki/Convex_hull
* --------------------------------------------------------------------------
* convex hull of a region as polygon
get_region_convex (RegionSelected, Rows, Columns)
* trasform the polygon in a region
gen_region_polygon_filled (ConvexRegion, Rows, Columns)
* For avoiding to merge separeted parts, I erode a little the convex region
erosion_circle (ConvexRegion, RegionErosion, 1.5)
* Now I remove the selected region from its convex (erosed) region.
* In most of the case the results is the space between the branches
difference (RegionErosion, RegionSelected, RegionDifference)
* --------------------------------------------------------------------------
* I separate the space between the branches and I count the its number
* --------------------------------------------------------------------------
* connection
connection (RegionDifference, InsideRegions)
* I remove empy regions
select_shape (InsideRegions, InsideSelectedRegions, 'area', 'and', 1, 99999999)
* I count the regions
count_obj (InsideSelectedRegions,NumInsideRegions)
* I add the result to the array
NumBranches :=[NumBranches,NumInsideRegions]
endfor
我需要找到有很多分支的形状。但是只有 region_features 我无法完成这项工作。
基本上,我需要一个“分支因子”的分数。例如,一颗星会有相当高的分数,因为每个尖端都是一个分支。一个树枝的图片会得分高,因为它有许多较小的分支..球体或立方体得分低,因为它没有很多分支..
我试过面积和周长的比例,但是不够精确..
这里有 2 个样本.. 一个应该有高分,一个应该有低分:
这些只是解释我所说的分支的意思的示例。形状可以有任何形式。
没有,没有这个参数
也许您可以使用如下代码提取此参数:
* load image example
read_image(Image,'ppUXL.jpg')
* create 4 Regions
binary_threshold (Image, Region, 'max_separability', 'dark', UsedThreshold)
connection (Region, Regions)
count_obj (Regions,NumRegions)
NumBranches :=[]
* for every region in Regions
for i:=1 to NumRegions by 1
* select the region
select_obj (Regions, RegionSelected, i)
* --------------------------------------------------------------------------
* Here I want to calculate the region convex hull,
* i.e. the smallest region convex region that contains the selected region
* https://en.wikipedia.org/wiki/Convex_hull
* --------------------------------------------------------------------------
* convex hull of a region as polygon
get_region_convex (RegionSelected, Rows, Columns)
* trasform the polygon in a region
gen_region_polygon_filled (ConvexRegion, Rows, Columns)
* For avoiding to merge separeted parts, I erode a little the convex region
erosion_circle (ConvexRegion, RegionErosion, 1.5)
* Now I remove the selected region from its convex (erosed) region.
* In most of the case the results is the space between the branches
difference (RegionErosion, RegionSelected, RegionDifference)
* --------------------------------------------------------------------------
* I separate the space between the branches and I count the its number
* --------------------------------------------------------------------------
* connection
connection (RegionDifference, InsideRegions)
* I remove empy regions
select_shape (InsideRegions, InsideSelectedRegions, 'area', 'and', 1, 99999999)
* I count the regions
count_obj (InsideSelectedRegions,NumInsideRegions)
* I add the result to the array
NumBranches :=[NumBranches,NumInsideRegions]
endfor