Concurrent implementation of .ppm
images convolution filter.
The application uses Python multiprocessing
module for concurrency and numpy.array
for image processing.
To run the app first create the virtual environment:
python -m venv cf-venv
Then start the environment:
source cf-venv/bin/activate
Next install dependencies:
pip install -r requirements.txt
Start the app:
python conv.py [ARGS]
In this mode the app applies convolution filer to given image.
python conv.py [IMAGE] [BLUR] [NUMBER_OF_WORKERS] [MEASURE_TIME?]
- IMAGE - name of image file to apply filter on
- BLUR - choose blur matrix to use
- NUMBER_OF_WORKERS - number of workers (processes) to use
- MEASURE_TIME - optional,
t
for printing execution time
python conv.py image.ppm blur1 8 1 t
In this mode the app applies convolution filer many times on consecutive numbers of workers.
Time results are being printed as csv
to standard output.
python conv.py bench [IMAGE] [MAX_WORKERS] [MAX_ITERATIONS]
- IMAGE - name of image file to apply filter on
- MAX_WORKERS - maximal number of workers to run benchmark on
- MAX_ITERATIONS - maximal number of iteration to run benchmark on
python conv.py bench image.ppm 12 50
Convolution filter is used to blur or sharpen images. This effect is achieved by substituting each pixel by weighted arithmetic mean of it and its neighbours.
The type and strength of filter can be adjusted using different weights. In this implementation they are represented as matrix stored in conv.api.MATRIX
.
Result of computation is a set of results of computing individual pixels. Each pixel result is depending only of state of its neighbours. That makes this problem perfect for concurrent computations.
Source image is divided into n
slices, where n
is the number of concurrent workers to use. Each slice is cut on y
axis (so rows are not affected).
They a new system process is being created for every slice. In order to process edge pixels, each slice is being padded by edge values of previous and next slice.
Slices are copies of original image and are stored in each process's memory.
Workers apply filter on each pixel in the loop. Before processing next iterations the worker synchronizes edge values with its neighbours, so that there is no inconsistency in end result.
- Intel Core i7 8th gen 2.2Ghz (max. 4.1Ghz) 6x
- 32GB DDR4
- macOS Catalina
MAX_WORKERS=24
MAX_ITERATIONS=10
The project was made by Jakub Riegel during Software Engineering course on Poznan University of Technology