sharkyenergy
sharkyenergy

Reputation: 4173

Halcon - Get a score for branches

I need to find shapes that have many branches.. But with only the region_features i'm not able to make this work.

basically, I'd need a score for a "branch factor".. for example, a star would have a rather high score, since each tip would be a branch.. a picture of a tree-branch would have a high score, since it has many smaller branches.. A sphere, or a cube would have a low score since it does not have many branches..

I have tried with the proportion between area and circumference, but its not precise enough..

here are 2 samples.. one that hsould have a high score, and one that should have a low score:

enter image description here enter image description here

These are only samples to explain what I mean by branches.. the shapes can have any form..

Upvotes: 0

Views: 156

Answers (1)

Andrea Mannari
Andrea Mannari

Reputation: 1012

No, there is not this kind of parameter.

Maybe you can extract this parameter with a code like:

* 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

test.jpg

Upvotes: 1

Related Questions