# Arc support based detector

This folder contains the implementation of the arc adjacency matrix based
detector according to my understanding of the
[original article](https://ieeexplore.ieee.org/document/8802276).

## 3rd party code

The implementation makes use of Line segment detector(LSD) which is under GNU
Affero
General Public License.
LSD was modified according to the changes mentioned in the ellipse detector. The
modifications are stated in the lsd.c file line:96-102 and at the places where
the change took place.

## Usage

Enter the build folder and run build.sh bash script or run: cmake .. && make (if
using the provided docker file this step can be skipped).
The build folder contains a simple run.sh script with prefilled parameters and
their recommended ranges. The detector requires 11 parameters and then paths to the images.

```bash
#!/bin/bash



            #Parameters          #defVal     #Range    
sig=2.5     #sigma               2            <0,5>     sets the sigma of Gaussian blur
s=1.0       #scale               1            <0.3,1>   scales down the image as working on scaled down image may result in more accurate detection
p=0         #polarity            0            {-1,0,1}  selects polarity of detected ellipses
R=0.5       #Ratio               0.7          <0.6,1.2> Ratio between support inliers and arc length
Tr=0.5      #Treshold            0.6          <0.4,0.8> keeps ellipses with goodness measure > Treshold 
eps=1.25    #eps                 1.25         <1,3>     validates an inlier if Rosin distance < eps
Ss=8        #Searchsize          8            <4,16>    sets search size of the statistical area
Tcover=2.8  #Tcoverage           1.57         <1.8,3.9> arc combination with coverage > Tcover are used in ellipse fiting
show=0      #show                0            {0,1}     displays the image with extracted ellipses if set to 1
#DISCLAIMER! if using the provided docker file show must always be set to 0
out="../../extracted/ASBED/"    #output dirrectory path


./arc_support ${sig} ${s} ${p} ${R} ${Tr} ${eps} ${Ss} ${Tcover} ${show}  ${out} $@

```

the detector then can be used by running the script with the path to the images,
as an example the images in the test_images folder are used.

```bash
./run.sh ../../test_images/*
```

## Examples

Running the program with the following arguments on test_images/sint.png .

```
            #Parameters          defVal       Range    
sig=2.5     #sigma               2            <0,5>
s=0.8       #scale               1            <0.3,1>
p=0         #polarity            0            {-1,0,1}
R=0.5       #Ratio               0.7          <0.6,1.2>
Tr=0.5      #Treshold            0.6          <0.4,0.8>
eps=1.25    #eps                 1.25         <1,3>
Ss=10       #Searchsize          8            <4,16>
Tcover=3    #Tcoverage           1.57         <1.83,3.93>
```

![extraction on sint.jpg with the parameters above](examples/sint-all.jpg)

```
            #Parameters          defVal       Range    
sig=2.5     #sigma               2            <0,5>
s=0.8       #scale               1            <0.3,1>
p=1         #polarity            0            {-1,0,1}
R=0.5       #Ratio               0.7          <0.6,1.2>
Tr=0.5      #Treshold            0.6          <0.4,0.8>
eps=1.25    #eps                 1.25         <1,3>
Ss=10       #Searchsize          8            <4,16>
Tcover=3    #Tcoverage           1.57         <1.83,3.93>
```

![extraction on sint.jpg with the parameters above](examples/sint-positive.jpg)

```
            #Parameters          defVal       Range    
sig=2.5     #sigma               2            <0,5>
s=0.8       #scale               1            <0.3,1>
p=-1        #polarity            0            {-1,0,1}
R=0.5       #Ratio               0.7          <0.6,1.2>
Tr=0.5      #Treshold            0.6          <0.4,0.8>
eps=1.25    #eps                 1.25         <1,3>
Ss=10       #Searchsize          8            <4,16>
Tcover=3    #Tcoverage           1.57         <1.83,3.93>
```

![extraction on sint.jpg with the parameters above](examples/sint-negative.jpg)
Running the program with the following arguments on test_images/sint.png .

```
            #Parameters          defVal      Range    
sig=2.5     #sigma               2            <0,5>
s=0.8       #scale               1            <0.3,1>
p=-1        #polarity            0            {-1,0,1}
R=0.5       #Ratio               0.7          <0.6,1.2>
Tr=0.5      #Treshold            0.6          <0.4,0.8>
eps=1.25    #eps                 1.25         <1,3>
Ss=10       #Searchsize          8            <4,16>
Tcover=3    #Tcoverage           1.57         <1.83,3.93>
```

![extraction on test-color.jpg with the parameters above](examples/test-color.jpg)

Running the program with the following arguments on tests_images/logs.jpg .

```
            #Parameters          defVal       Range    
sig=2.5     #sigma               2            <0,5>
s=0.8       #scale               1            <0.3,1>
p=0         #polarity            0            {-1,0,1}
R=0.5       #Ratio               0.7          <0.6,1.2>
Tr=0.5      #Treshold            0.6          <0.4,0.8>
eps=1.25    #eps                 1.25         <1,3>
Ss=10       #Searchsize          8            <4,16>
Tcover=3    #Tcoverage           1.57         <1.83,3.93>
```

![extraction on logs.jpg with the parameters above](examples/logs.jpg)

Running the program with the following arguments on test_images/Brown-eggs.jpg .

```
            #Parameters          defVal       Range    
sig=2.5     #sigma               2            <0,5>
s=0.8       #scale               0.8          <0.3,1>
p=0         #polarity            0            {-1,0,1}
R=0.8       #Ratio               0.8          <0.6,1.2>
Tr=0.6      #Treshold            0.6          <0.4,0.8>
eps=1.25    #eps                 1.25         <1,3>
Ss=10       #Searchsize          10           <4,16>
Tcover=3    #Tcoverage           1.57         <1.83,3.93>
```

![extraction on Brown-eggs.jpg with the parameters above](examples/Brown-eggs.jpg)

