How to Implement a Motion Blur Filter using Python

2 min readFeb 1, 2023

Natural motion blurs occur when an image subject is moving faster than the exposure time of a camera. Motion blur filters, on the other hand, seek to emulate this effect on stationary image subjects with the help of advanced modeling techniques.

Thankfully, the below API solution makes it possible to impart a motion blur effect on your image without having to make any complex calculations yourself. You can simply install the below SDK, call the function, and specify the radius, sigma and angle of your motion blur to create a customizable visual effect.

Run the following command to install the Python SDK:

pip install cloudmersive-image-api-client

Then add the imports and call the function:

from __future__ import print_function
import time
import cloudmersive_image_api_client
from import ApiException
from pprint import pprint

# Configure API key authorization: Apikey
configuration = cloudmersive_image_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'

# create an instance of the API class
api_instance = cloudmersive_image_api_client.FilterApi(cloudmersive_image_api_client.ApiClient(configuration))
radius = 56 # int | Radius in pixels of the blur operation; a larger radius will produce a greater blur effect
sigma = 56 # int | Sigma, or variance, of the motion blur operation
angle = 56 # int | Angle of the motion blur in degrees
image_file = '/path/to/inputfile' # file | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.

# Perform a motion blur on the input image
api_response = api_instance.filter_motion_blur(radius, sigma, angle, image_file)
except ApiException as e:
print("Exception when calling FilterApi->filter_motion_blur: %s\n" % e)

To use this service for free, you’ll need to get a free-tier Cloudmersive API Key by registering a free account on our website. This will allow up to 800 API calls per month with zero additional commitments.




There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.