You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -113,81 +113,138 @@ For a pixel along the edge or corner, like pixel 15, we would still look for all
113
113
114
114
If you apply the above algorithm to each pixel in the image, the result should look like a blurry, out-of-focus version of the original.
115
115
116
-
### 6.) Brightness Adjustment Filter
117
-
-**Flag:**`-B <value>`
118
-
-**Description:** Increases or decreases the brightness of the image by adding a fixed value to each pixel's R, G, and B channels. The value should be an integer—positive to increase, negative to decrease.
119
-
-**Usage examples:**
120
-
```sh
121
-
./filter -B 40 input.bmp output.bmp # Increase brightness by 40
122
-
./filter -B -30 input.bmp output.bmp # Decrease brightness by 30
123
-
```
116
+
### 5.) The Invert Algorithm
117
+
118
+
The “invert” filter creates a photographic negative of an image by reversing the RGB values.
119
+
If a pixel has a value of 0 (no light), its inverted value becomes 255 (full light), and vice-versa.
120
+
121
+
To compute the inverted colors, subtract each channel from 255:
122
+
123
+
invertedRed = 255 - originalRed
124
+
invertedGreen = 255 - originalGreen
125
+
invertedBlue = 255 - originalBlue
126
+
127
+
However, simply inverting can sometimes change brightness unnaturally.
128
+
To preserve the original brightness, we compute brightness for both original and inverted pixels, then apply a correction to match brightness levels.
129
+
Finally, each pixel’s red, green, and blue values are set to the brightness-corrected inverted values.
130
+
Applying this to every pixel produces a clean color-negative effect.
131
+
132
+
133
+
134
+
### 6.) The Brightness Adjustment Algorithm
135
+
136
+
Brightness adjustment increases or decreases the light intensity of each pixel.
137
+
138
+
To brighten or darken, a fixed value is added to each color channel:
139
+
140
+
newRed = originalRed + value
141
+
newGreen = originalGreen + value
142
+
newBlue = originalBlue + value
143
+
144
+
145
+
To ensure values stay valid, the results are clamped between 0 and 255:
146
+
147
+
if newValue > 255 -> 255
148
+
if newValue < 0 -> 0
149
+
150
+
151
+
A positive value increases brightness; a negative value decreases it.
152
+
Applied across the image, this produces a uniformly brighter or darker picture.
153
+
154
+
### 7.) The Vignette Algorithm
155
+
156
+
The vignette filter darkens the edges of an image to draw attention toward the center.
157
+
158
+
We compute the distance of each pixel from the image center:
159
+
160
+
distance = sqrt((x - centerX)² + (y - centerY)²)
161
+
162
+
163
+
Then calculate a scaling factor based on distance:
Each color channel is multiplied by this factor, so pixels farther from the center get darker.
169
+
170
+
The result is a cinematic, spotlight-like fade toward the image edges.
171
+
172
+
### 8.) The Threshold (Black & White) Algorithm
173
+
174
+
Thresholding converts an image into pure black-and-white.
175
+
176
+
First, compute the pixel’s grayscale average:
177
+
178
+
avg = (Red + Green + Blue) / 3
179
+
124
180
125
-
### 6.) The Threshold Algorithm
181
+
If the result is 128 or greater, the pixel becomes white.
182
+
Otherwise, it becomes black:
126
183
127
-
The “threshold” filter converts a colorful image into a pure black-and-white one based on pixel intensity.
184
+
if avg >= 128 -> (255, 255, 255)
185
+
else -> (0, 0, 0)
128
186
129
-
For each pixel, the intensity is calculated as the average of its red, green, and blue values:
130
187
131
-
\[
132
-
\text{intensity} = \frac{(R + G + B)}{3}
133
-
\]
188
+
This filter produces a strong high-contrast binary image, similar to printed text or stencil art.
134
189
135
-
If the intensity is **greater than or equal to 128**, the pixel is set to **white** (`R = G = B = 255`).
136
-
Otherwise, it is set to **black** (`R = G = B = 0`).
190
+
### 9.) The Edge Detection Algorithm (Sobel Operator)
137
191
138
-
This results in a high-contrast, two-tone image where all intermediate shades are eliminated — essentially a hard binary “black-and-white” conversion.
192
+
Edge detection highlights boundaries and sharp transitions in an image.
139
193
194
+
We apply the Sobel Kernel in both X and Y directions:
140
195
141
-
### 7.) The Edge Detection (Sobel) Algorithm
196
+
Gx = horizontal edge kernel
197
+
Gy = vertical edge kernel
142
198
143
-
The “edge detection” filter highlights sharp changes in pixel intensity, producing a sketch-like outline of the image.
144
199
145
-
For each pixel, the horizontal and vertical gradients are calculated using a 3×3 Sobel kernel applied to the surrounding pixels:
200
+
For each pixel, we compute weighted sums for both kernels for each color channel:
146
201
147
-
Horizontal (Gx):
148
-
-1 0 1
149
-
-2 0 2
150
-
-1 0 1
202
+
gradient = sqrt((Gx²) + (Gy²))
151
203
152
-
Vertical (Gy):
153
-
-1 -2 -1
154
-
0 0 0
155
-
1 2 1
156
204
157
-
The gradient magnitude for each color channel is then computed as:
205
+
The result is then clamped between 0 and 255.
158
206
159
-
value
160
-
=
161
-
𝐺
162
-
𝑥
163
-
2
164
-
+
165
-
𝐺
166
-
𝑦
167
-
2
168
-
value=
169
-
Gx
170
-
2
171
-
+Gy
172
-
2
173
-
207
+
Pixels with strong intensity changes become bright (edges), while uniform areas appear dark — producing a clean outline/edge-map of the image.
174
208
209
+
### 10.) The Glow Algorithm
175
210
176
-
The result is clamped between 0 and 255 and replaces the original pixel value. This produces a monochrome image where edges are highlighted, giving a pencil-sketch effect.
211
+
Glow enhances bright areas and gives a soft-highlight aura.
177
212
178
-
---
213
+
Steps:
179
214
180
-
### 8.) The Glow Algorithm
215
+
Make a copy of the original image
181
216
182
-
The “Glow” filter gives bright regions of an image a soft, luminous halo, similar to a cinematic bloom effect. This filter works by blending the original image with a blurred version of itself.
217
+
Apply a mild blur to the copy
183
218
184
-
The algorithm first creates a copy of the image and applies a mild box blur (using a smaller kernel than the main blur filter) to it. Then, for each pixel, the final color values are calculated by combining the original pixel's color with the new blurred pixel's color using a weighted average:
The resulting values are rounded to the nearest integer and capped at 255. This process brightens the image and causes the light to "bleed" from bright areas into darker ones, creating a soft, luminous effect.
223
+
224
+
A small blend value (e.g., 0.3) produces a natural glow effect without washing out details.
225
+
226
+
This creates a dreamy, halo-like enhancement around highlights — similar to portrait photography glow effects.
227
+
228
+
### 11.) The Oil-Paint Algorithm
229
+
230
+
The oil-paint effect simulates brush-stroke texture by grouping pixels based on intensity bins.
231
+
232
+
For each pixel:
233
+
234
+
Look at neighboring pixels within a radius
235
+
236
+
Compute each neighbor’s intensity bucket:
237
+
238
+
intensity = (R + G + B) / 3
239
+
240
+
241
+
Count how many pixels fall into each intensity level
242
+
243
+
Select the most common intensity bin
244
+
245
+
Set the pixel’s final color to the average color of that bin
246
+
247
+
This produces thick, paint-style textures and smoothed color patches, mimicking traditional oil-painting strokes.
191
248
192
249
### Usage
193
250
@@ -202,14 +259,84 @@ To apply a filter via command-line:
202
259
-`t`: threshold
203
260
-`d`: edge detection
204
261
-`B <value>`: brightness
262
+
-`o`: oilpaint
263
+
264
+
#### Examples:
265
+
266
+
```bash
267
+
# Grayscale a PNG image
268
+
./filter.exe -g input.png output.png
269
+
# Sepia on JPEG image
270
+
./filter.exe -s input.jpg output.jpg
271
+
# Blur a BMP image
272
+
./filter.exe -b input.bmp output.bmp
273
+
# Chain multiple filters
274
+
./filter.exe -g -b input.png output.png
275
+
# Convert format (PNG to JPEG)
276
+
./filter.exe -g input.png output.jpg
277
+
# Brightness adjustment
278
+
./filter.exe -B 40 input.jpg output.jpg
279
+
```
280
+
281
+
You can also chain multiple filters by supplying multiple tags (e.g., `./filter.exe -v -g input.bmp output.bmp` for vignette then grayscale).
205
282
206
-
Example for glow:
207
-
./filter -G input.bmp output.bmp
283
+
## Supported Image Formats
208
284
209
-
For vignette:
285
+
The Image-Filtering tool supports multiple image formats:
286
+
287
+
-**BMP**: 24-bit uncompressed BMP files
288
+
-**PNG**: PNG images with RGB color space (supports various PNG formats including RGBA, grayscale, palette - automatically converted to RGB)
289
+
-**JPEG**: JPEG images with RGB color space (supports grayscale and RGB JPEGs)
290
+
291
+
### Format Auto-Detection
292
+
293
+
The tool automatically detects the input image format based on file signatures (magic bytes). The output format is determined by the file extension of the output filename. You can convert between formats by simply changing the output file extension.
0 commit comments