https://github.com/jonaylor89/image-segmentation
CMSC 630 Image Analysis Project 2
https://github.com/jonaylor89/image-segmentation
Last synced: 8 months ago
JSON representation
CMSC 630 Image Analysis Project 2
- Host: GitHub
- URL: https://github.com/jonaylor89/image-segmentation
- Owner: jonaylor89
- License: mit
- Created: 2020-04-04T20:49:15.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-09-19T23:29:22.000Z (9 months ago)
- Last Synced: 2025-10-09T11:37:50.352Z (8 months ago)
- Language: Python
- Size: 6.87 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CMSC 630 Project 2
### Image Segmentation and Clustering
## Overview
This program is designed to take a batch of images as input, and run given set of operations on them (Edge Detection, Histogram Clustering, Histogram Thresholding, Dilation, and Erosion). All of these operations output a new image for each image in the batch. A TOML file in the root directory of the source code is used to configure the operations such as the strength of noise and the weights for filters. All important operations are implemented from scratch except for array operations that use the third-party mathematics library `numpy`.
### Usage
Usage: main.py [OPTIONS]
Options:
-c, --config PATH [default: config.toml]
--help Show this message and exit.
### Execution
git clone https://github.com/jonaylor89/image-segmentation.git
cd image-segmentation
uv sync
uv run python main.py
Or
docker run -it -v $HOME/Repos/CMSC_630_Project_2/datasets:/app/datasets jonaylor/cmsc_project_2
*(this should pull the image already on dockerhub so the image won't be built locally)*
## Implementation
The programming language of choice for this project was python. The high level reason for making the decision to write everything in python was that it gives the ability to rapidly develop and integrate each operation as well as for python's `numpy` library which allows for idiomatic and fast array operations. Python's fairly obvious downside is its speed. To mitigate the problem of speed for the image operations, `numba` , a third-party python library used for mathematics, is being used. `numba` has a python function decorator for just-in-time compiling functions to machine code before executing. Using this decorator on functions that use heavy math and looping (i.g. convolving) provides major speed increases with speeds similar to using a lower level compiled language like C/C++ or Rust. Compilation time effects the first image in the batch, but every image thereafter uses the precompiled machine code. Image batches, rather than being operated on synchronously, are thrown into a process pool where a preconfigured number of worker processes pulls images off a queue and runs them through the operation pipelines.
**Full Third-Party Dependency List**
# pyproject.toml dependencies
pillow>=11.3.0 # reading and writing images
numpy>=2.3.3 # fast array operations
click>=8.3.0 # command line interface utility
numba>=0.62.0 # just-in-time compiler for operations
toml>=0.10.2 # reading configuration file
tqdm>=4.67.1 # progress bar
*These can be found in the pyproject.toml at the root of the source code*
---
## Results
The output of this program can be seen in two places. The first is in the output directory specified in the `toml` configuration file. In the output directory there are the gray scale images from each operation with the file name `{operation}_{original image}.BMP` (e.g. `edges_svar53.BMP`).
canny_edge_detection(img_array: np.array) -> np.array

Original

After Edge Detection
dilate(img_array: np.array, win: int = 1) -> np.array

original

Segmented and Dilated
erode(img_array: np.array, win: int = 1) -> np.array

original

Segmented and Eroded
histogram_thresholding(img_array: np.array) -> np.array

original

segmented
histogram_clustering(img_array: np.array) -> np.array
---

original

segmented