Skip to content

Concurrent implementation of image convolution filter using Python's multiprocessing

Notifications You must be signed in to change notification settings

jakubriegel/convolution_filter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

convolution filter

about

Concurrent implementation of .ppm images convolution filter. The application uses Python multiprocessing module for concurrency and numpy.array for image processing.

table of contents

run it

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]

cli

filter mode

info

In this mode the app applies convolution filer to given image.

command

python conv.py [IMAGE] [BLUR] [NUMBER_OF_WORKERS] [MEASURE_TIME?]

arguments

  • 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

example

python conv.py image.ppm blur1 8 1 t

benchmark mode

info

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.

command

python conv.py bench [IMAGE] [MAX_WORKERS] [MAX_ITERATIONS]

arguments

  • 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

example

python conv.py bench image.ppm 12 50

algorithm

the filter

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.

concurrency

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.

sample benchmark

machine

  • Intel Core i7 8th gen 2.2Ghz (max. 4.1Ghz) 6x
  • 32GB DDR4
  • macOS Catalina

parameters

MAX_WORKERS=24
MAX_ITERATIONS=10

results

image

credits

The project was made by Jakub Riegel during Software Engineering course on Poznan University of Technology

put logo

About

Concurrent implementation of image convolution filter using Python's multiprocessing

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages