---
# System prepended metadata

title: Readme

---

# Readme
* Images are placed in "images" folder.
    * 66075.jpg is from BSD500 dataset-"train" folder
    * oranges.jpg is from 
[reference link]
https://github.com/gaomingqi/Chan-Vese-model/tree/master/images
    * other images is generated by ppt
* Matlab code (open source)
[reference link]
https://www.mathworks.com/matlabcentral/fileexchange/12711-level-set-for-image-segmentation?s_tid=srchtitle_Distance%20Regularized%20Level%20Set%20Evolution%20and%20Its%20Application%20to%20Image%20Segmentation_1#functions_tab
* Paper Ref: 
    C. Li, C. Xu, C. Gui, M. D. Fox, 
    "Distance Regularized Level Set Evolution and Its Application to Image Segmentation", 
    IEEE Trans. Image Processing, vol. 19 (12), pp. 3243-3254, 2010.
* User Guide for `DRLSE.m`:
    *  Step 1.    Read image
    *  Step 2.    Set number of iterations : total iterations = iter_inner * iter_outer
    *  Step 3.    Second part of parameter setting : users can freely modify the parameter values listed below.
        *  tol = 10 ; % the tolerance for stopping condition
        *  lambda = 5 ; % coefficient of the weighted length term L(phi).
             % The value of lambda needs to be positive.
        * alfa = -3 ;  % coefficient of the weighted area term A(phi).
             % If alfa < 0, it means that the area of the negative values of LSF is larger.
             % On the contrary, if alfa > 0, ~ positive values of LSF is larger.
        * c0 = 2 ; % binary steps (for initial LSF)
         % The bigger the absolute value of c0, 
         % the slower the speed of the evolution process.

    * Step 4.   Construct initial LSF : Users are free to design.  
    * Step 5.   Save the evolution process as gif : provide the output path & gif name.
    
    
---

==The Experiments 1 to 7 below are not in our poster!==


---

## Experiment 1: How to choose $c_0$ (the binary step)
The initial LSF is a huge frame.
You can add the below code in the **Step 4** of `DRLSE.m` :
```
initialLSF = c0*ones(size(Img)); % Given the value of initial LSF
[m_img,n_img]=size(Img) ;
pickm=ceil(m_img/30) ;
pickn=ceil(n_img/30) ;
initialLSF(pickm:m_img-pickm,pickn:n_img-pickn)=-c0; 
```
![](https://hackmd.io/_uploads/Hyu7RC0P3.jpg)
* To visualize the evolution of LSF such as figures ( d ) and ( f ), you can remove the comment in lines 211~215 of `DRLSE.m`. 

In ( c ) and ( e ), we observe that the larger the value of $c_0$, the slower the speed of the evolution process. This is because a larger $c_0$ requires more computation during the evolution of the LSF. Therefore, for subsequent experiments and the experiments presented in our poster, we set the binary step as $c_0=2$.


---

## Experiment 2: Choice of initial LSF
The initial LSF is generated by `preprocess_LSF_fix_numframe.m`.
You can add the below code in the **Step 4** of `DRLSE.m` :
```
initialLSF = c0*ones(size(Img)); % Given the value of initial LSF
number = 2 ; % #frame
bd = 20 ; % the width from the image boundary
initialLSF = preprocess_LSF_fix_numframe(Img,number,bd,c0) ;
```
1. ![](https://hackmd.io/_uploads/r1lee1CDh.jpg)
In ( b ), the outer region of the largest frame is positive value, and it alternates between negative and positive values as you move inward. The red frame represents the zero level contour.

    By setting $\alpha<0$, we aim to expand the negative value area, causing the outer frame to move outward and the inner frame to move inward, as depicted in ( c ). With additional iterations, the zero level contour will eventually vanish, leading to no object being segmented in the end.
    * iterations = iter_inner$\times$iter_outer = $5\times 5=25$

2. ![](https://hackmd.io/_uploads/BkUSrkCP2.jpg)
In ( b ), the outer region of the largest frame is positive value, and it alternates between negative and positive values as you move inward. The red frame represents the zero level contour.

    By setting $\alpha>0$, we aim to expand the positive value area, causing the outer frame to move inward and the inner frame to move outward, as depicted in ( c ). With additional iterations, the two zero level contours will merge and eventually vanish, resulting in no object being segmented in the end.
    * iterations = iter_inner$\times$iter_outer = $5\times 10=50$
   
3. ![](https://hackmd.io/_uploads/BywxDJCwn.jpg)
In ( b ), the outer region of the largest frame is positive value, and it alternates between negative and positive values as you move inward. The red frame represents the zero level contour.

    By setting $\alpha<0$, we aim to expand the negative value area, causing the largest frame to move outward, the second frame to move inward, and the smallest frame to move outward, as depicted in ( c ).
    
    With additional iterations, the second and smallest frames will merge and eventually vanish, while the largest frame will expand and eventually disappear. As a result, no object will be segmented in the end.
    * iterations = iter_inner$\times$iter_outer = $5\times 10=50$

4. ![](https://hackmd.io/_uploads/ByQOYyAvh.jpg)
In ( b ), the outer region of the largest frame is positive value, and it alternates between negative and positive values as you move inward. The red frame represents the zero level contour.

    By setting $\alpha>0$, we aim to expand the positive value area, causing the largest frame to move inward, the second frame to move outward, and the smallest frame to move inward, as depicted in ( c ).
    
    With additional iterations, the largest and second frames will merge and eventually vanish, while the smallest frame will shrink and eventually disappear. As a result, no object will be segmented in the end.
    * iterations = iter_inner$\times$iter_outer = $5\times 20=100$

==Based on the observations in 1 to 4, we can deduce that in `preprocess_LSF_fix_numframe.m`, regardless of the number of frames we set, the outer region of the largest frame is always positive.==
    
==Additionally, regardless of the sign assigned to $\alpha$, the zero level contour in `preprocess_LSF_fix_numframe.m` may merge, shrink, expand, or eventually disappear. Consequently, this initial LSF is ineffective for segmenting any objects. Hence, we can conclude that such an initial LSF is not effective in the DRLSE model.==


---

## Experiment 3: Choice of initial LSF
The initial LSF is generated by `preprocess_LSF_many_frame.m`.
You can add the below code in the **Step 4** of `DRLSE.m` :
```
initialLSF = c0*ones(size(Img)); % Given the value of initial LSF
width = 15; % width of LSF
bd = 30 ; % the width from the image boundary 
initialLSF = preprocess_LSF_many_frame(Img,c0,width,bd) ;
```

1. ![](https://hackmd.io/_uploads/rkbqT10Dh.jpg)
In ( b ), the outer region of the largest frame is positive value, and it alternates between negative and positive values as you move inward. The red frame represents the zero level contour.

    By setting $\alpha<0$, we aim to expand the negative value area, causing the largest frame to move outward and the other frames to alternate between moving inward and outward, as depicted in ( c ).
    
    With additional iterations,the zero level contour may merge, shrink, expand, or eventually disappear. As a result, no object will be segmented in the end.
    * iterations = iter_inner$\times$iter_outer = $5\times 4=20$

2. ![](https://hackmd.io/_uploads/HypHbxRvh.jpg)
In ( b ), the outer region of the largest frame is positive value, and it alternates between negative and positive values as you move inward. The red frame represents the zero level contour.

    By setting $\alpha>0$, we aim to expand the positive value area, causing the largest frame to move inward and the other frames to alternate between moving outward and inward, as depicted in ( c ).
    
    With additional iterations,the zero level contour may merge, shrink, expand, or eventually disappear. As a result, no object will be segmented in the end.
    * iterations = iter_inner$\times$iter_outer = $5\times 7=35$

==Based on the observations in 1 and 2, we can deduce that in `preprocess_LSF_many_frame.m`, regardless of the distance or interval between adjacent frames, the outer region of the largest frame is always positive.==
    
==Additionally, regardless of the sign assigned to $\alpha$, the zero level contour in `preprocess_LSF_many_frame.m` may merge, shrink, expand, or eventually disappear. Consequently, this initial LSF is ineffective for segmenting any objects. Hence, we can conclude that such an initial LSF is not effective in the DRLSE model.==


---

## Experiment 4: Choice of initial LSF
The initial LSF is generated by `preprocess_LSF_Nrectangles.m`.
You can add the below code in the **Step 4** of `DRLSE.m` :
```
initialLSF = c0*ones(size(Img)); % Given the value of initial LSF
bd = 30 ; % the width from the image boundary
len = 15; % length of rectangle
width = 15 ; % width of rectangle
initialLSF = preprocess_LSF_Nrectangles(Img,bd,len,width,c0) ;
```

1. ![](https://hackmd.io/_uploads/SJgl7xAP2.jpg)
In ( a ), the outer region of all rectangles is positive value, while the inner region is negative. The red frame represents the zero level contour. By setting $\alpha<0$, we aim to expand the negative value area, causing all rectangles to move outward, as depicted in ( b ).
    * iterations = iter_inner$\times$iter_outer = $5\times 5=25$
   
    In ( c ), with additional iterations, the zero level contour will expand and then merge. Eventually, they will disappear and thus no object will be segmented in the end.
    * iterations = iter_inner$\times$iter_outer = $5\times 30=150$

2. ![](https://hackmd.io/_uploads/ryRqMjADh.jpg)
In ( a ), the outer region of all rectangles is positive value, while the inner region is negative. The red frame represents the zero level contour. By setting $\alpha>0$, we aim to expand the positive value area, causing all rectangles to move inward, as depicted in ( b ).
    * iterations = iter_inner$\times$iter_outer = $5\times 4=20$

    In ( c ), we set the iterations (iter_inner$\times$iter_outer) as $5\times 20=100$, and tolerance as $10$. The segmentation result shows that no object will be segmented after $45$ iterations through the stopping condition.
       
==Based on the observations in 1 and 2, regardless of the sign assigned to $\alpha$, the zero level contour in `preprocess_LSF_Nrectangles.m` may may either *(1) expand $\rightarrow$ merge $\rightarrow$ disappear* or *(2) shrink $\rightarrow$ not segment any objects / disappear*. Consequently, this initial LSF is ineffective for segmenting any objects. Hence, we can conclude that such an initial LSF is not effective in the DRLSE model.==


---

### Conclusions for Experiment 2 ~ 4
The common ground among these three initial LSFs is that their zero level contour intersects both the objects and the background. We speculate that an initial LSF can effectively segment objects only when it does not simultaneously encompass both the objects and the background. In the **Results and Discussion** section of our poster, we verify this hypothesis through the experiment, as illustrated in figures 3( c ) and 3( d ).


---

## Experiment 5: Circles that are very closely spaced
The initial LSF is a huge frame.
You can add the below code in the **Step 4** of `DRLSE.m` :
```
initialLSF = c0*ones(size(Img)); % Given the value of initial LSF
[m_img,n_img]=size(Img) ;
pickm=ceil(m_img/30) ;
pickn=ceil(n_img/30) ;
initialLSF(pickm:m_img-pickm,pickn:n_img-pickn)=-c0; 
```
![](https://hackmd.io/_uploads/HysKUa0wn.jpg)
In ( b ), the outer region of a huge frame is positive value, while the inner region is negative. The red frame represents the zero level contour. By setting $\alpha>0$, we aim to expand the positive value area, causing the huge frame to move inward.

In ( c ), we set the iterations (iter_inner$\times$iter_outer) as $10\times 100=1000$, and tolerance as $1$. The segmentation result shows that most objects will be segmented after $530$ iterations through the stopping condition. Note that the circles in the third and fourth columns cannot be segmented entirely. ==This limitation arises from the insufficient number of pixels in the adjacent circles for segmentation. Consequently, the number of object pixels also affects the performance of the level set method for image segmentation.==


---

## Experiment 6: Reset phi (LSF) per 20 steps
The initial LSF is two lines.
You can add the below code in the **Step 4** of `DRLSE.m` :
```
initialLSF = c0*ones(size(Img)); % Given the value of initial LSF
initialLSF(:,1:20)=-c0;
initialLSF(:,(end-20):end)=-c0;
```
![](https://hackmd.io/_uploads/r1N0blydh.jpg)
In ( c ) and ( e ), we observe that the latter did not enclose the hair on the right side of the ostrich's neck. As shown in (d) and (f), the latter is missing some details at the edges of the object. This is because we reset the LSF every 20 steps for (e) and (f). ==Hence, we can conclude that resetting the LSF does not lead to good performance of the DRLSE model for image segmentation.==


---

## Experiment 7: Change distance regularization term
In the paper, the distance regularization term involves $\text{div}(d_p(|\nabla\phi|)\nabla\phi).$
That is, 
$$
\frac{\partial}{\partial x}(d_p(|\nabla\phi|\cdot\phi_x)+\frac{\partial}{\partial y}(d_p(|\nabla\phi|\cdot\phi_y).
$$
In original code, the distance regularization term in line 89 of `drlse_edge.m` is
![](https://hackmd.io/_uploads/HJ6GPlyOn.png)

Intuitively, in the line 92 of `drlse_edge.m` is
![](https://hackmd.io/_uploads/Hyh0PgJdh.png)

![](https://hackmd.io/_uploads/HyGEKlkd2.jpg)
In ( e ) and ( f ), we observe that when changing the distance regularization term to an intuition code, the performance of segmentation get worse. 

We speculate that the reason for this is because the del2 calculation of the Laplacian is more accurate with a time interval of one unit length, compared to the gradient with a time interval of two unit lengths. Therefore, replacing a portion of the div(...) calculation with del2 would likely improve the results.
