This repository contains the implementation of the Random Walker Algorithm for image segmentation. This technique is part of a computational approach to segmenting images based on probability calculations and pixel value analysis.
The Random Walker Algorithm is a powerful method for image segmentation that treats pixel nodes in an image as a part of a graph. Segmentation is achieved by marking nodes and calculating the probability of a neighbor taking the same pixel value, inversely proportional to the difference between the pixel values.
The Random Walk Algorithm for image segmentation is based on the following steps and formulas:
The Random Walk Algorithm for image segmentation is based on the following steps and formulas:
-
Node Marking: The nodes in the image are marked based on the following criteria:
- Let
$p(i, j)$ be the pixel value at position (i, j) in the image. - Mark the nodes as follows:
- If
$p(i, j) > 110$ , then mark as 255 (white). - If
$p(i, j) < 75$ , then mark as 0 (black).
- If
- Let
-
Matrix Operations: All the unmarked nodes will be marked in subsequent steps. The key formula in the Random Walk Algorithm for image segmentation is:
$$L_u \cdot X = (-B)^T \cdot M$$ Where:-
$L_u$ is a submatrix of the L matrix containing information about all the unmarked to unmarked nodes. -
$X$ is the matrix representing probabilities. -
$B^T$ is a submatrix of the L matrix that contains inforation about all the unmarked nodes to marked nodes. -
$M$ matrix is defined for zero and 255 class$M_0$ and$M_{255}$ .
-
-
Calculating Probabilities: First, calculate
$X$ using the formula:$$X = L^{-1} \cdot (B^T) \cdot M$$ where$L^{-1}$ is the inverse of matrix$L$ ,$B^T$ is the transpose of matrix$B$ , and$M$ is the predefined matrix.The probability for pixel
$k$ taking the value 0 is given by the corresponding element in matrix$X$ for$M_0$ , which can be represented as:$$P(k \text{ takes value } 0) = X_k \text{ for } M_0$$ where$X_k$ is the k-th element in the matrix$X$ .
The algorithm's performance is evaluated based on the accuracy of segmentation. The accuracy is calculated as:
Overall accuracy achieved: 93.682%
- Run the provided Jupyter Notebook: ImageSegmentation.ipynb.
- To process a different image, change the image path in the notebook accordingly.
- The notebook includes code and visualizations demonstrating the segmentation process.
- Python
- Numpy
- Matplotlib
- (Any other libraries used in the project)
- Improving the algorithm to handle more complex image structures.
- Optimizing performance for large-scale images.
- Exploring the use of the algorithm in various application areas such as medical imaging or satellite imagery.
This project is open-source and available under the MIT License.