eienmojiki commited on
Commit
ad0c787
·
1 Parent(s): 41bdd67

Added motion blur filter and fixed duplicate controls.

Browse files

- Introduced motion blur filter with configurable kernel size
- Removed duplicate control initialization in app.py
- Updated filter registry with motion blur defaults
- Added kernel size validation for motion blur
- Improved code organization in filters.py

Files changed (2) hide show
  1. app.py +2 -0
  2. filters.py +31 -1
app.py CHANGED
@@ -16,6 +16,8 @@ def create_app():
16
  # Re-initialize controls and filter_names after adding the new filter
17
  controls = create_filter_controls()
18
  filter_names = list(registry.filters.keys())
 
 
19
 
20
  filter_groups = {} # Store filter groups
21
 
 
16
  # Re-initialize controls and filter_names after adding the new filter
17
  controls = create_filter_controls()
18
  filter_names = list(registry.filters.keys())
19
+ controls = create_filter_controls()
20
+ filter_names = list(registry.filters.keys())
21
 
22
  filter_groups = {} # Store filter groups
23
 
filters.py CHANGED
@@ -108,4 +108,34 @@ def pixelize(image, pixel_size: int = 10):
108
  # Resize back to the original size with nearest neighbor interpolation
109
  pixelized_image = cv2.resize(small_image, (width, height), interpolation=cv2.INTER_NEAREST)
110
 
111
- return pixelized_image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  # Resize back to the original size with nearest neighbor interpolation
109
  pixelized_image = cv2.resize(small_image, (width, height), interpolation=cv2.INTER_NEAREST)
110
 
111
+ return pixelized_image
112
+
113
+ @registry.register("Motion Blur", defaults={
114
+ "kernel_size": 10,
115
+ }, min_vals={
116
+ "kernel_size": 1,
117
+ }, max_vals={
118
+ "kernel_size": 50,
119
+ }, step_vals={
120
+ "kernel_size": 1,
121
+ })
122
+ def motion_blur(image, kernel_size: int = 10):
123
+ """
124
+ ## Apply a motion blur effect to the image.
125
+
126
+ **Args:**
127
+ * `image` (numpy.ndarray): Input image (BGR or grayscale)
128
+ * `kernel_size` (int): Size of the kernel
129
+
130
+ **Returns:**
131
+ * `numpy.ndarray`: Motion blurred image
132
+ """
133
+ # Create a horizontal kernel
134
+ kernel = np.zeros((kernel_size, kernel_size))
135
+ kernel[kernel_size//2, :] = np.ones(kernel_size)
136
+ kernel = kernel / kernel_size
137
+
138
+ # Apply the kernel to the image
139
+ motion_blurred_image = cv2.filter2D(image, -1, kernel)
140
+
141
+ return motion_blurred_image