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
124
117
125
-
### 6.) The Threshold Algorithm
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.
126
120
127
-
The “threshold” filter converts a colorful image into a pure black-and-white one based on pixel intensity.
121
+
To compute the inverted colors, subtract each channel from 255:
128
122
129
-
For each pixel, the intensity is calculated as the average of its red, green, and blue values:
123
+
invertedRed = 255 - originalRed
124
+
invertedGreen = 255 - originalGreen
125
+
invertedBlue = 255 - originalBlue
130
126
131
-
\[
132
-
\text{intensity} = \frac{(R + G + B)}{3}
133
-
\]
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.
134
131
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`).
132
+
137
133
138
-
This results in a high-contrast, two-tone image where all intermediate shades are eliminated — essentially a hard binary “black-and-white” conversion.
134
+
### 6.) The Brightness Adjustment Algorithm
139
135
136
+
Brightness adjustment increases or decreases the light intensity of each pixel.
140
137
141
-
### 7.) The Edge Detection (Sobel) Algorithm
138
+
To brighten or darken, a fixed value is added to each color channel:
142
139
143
-
The “edge detection” filter highlights sharp changes in pixel intensity, producing a sketch-like outline of the image.
140
+
newRed = originalRed + value
141
+
newGreen = originalGreen + value
142
+
newBlue = originalBlue + value
144
143
145
-
For each pixel, the horizontal and vertical gradients are calculated using a 3×3 Sobel kernel applied to the surrounding pixels:
146
144
147
-
Horizontal (Gx):
148
-
-1 0 1
149
-
-2 0 2
150
-
-1 0 1
145
+
To ensure values stay valid, the results are clamped between 0 and 255:
151
146
152
-
Vertical (Gy):
153
-
-1 -2 -1
154
-
0 0 0
155
-
1 2 1
147
+
if newValue > 255 -> 255
148
+
if newValue < 0 -> 0
156
149
157
-
The gradient magnitude for each color channel is then computed as:
158
150
159
-
value
160
-
=
161
-
𝐺
162
-
𝑥
163
-
2
164
-
+
165
-
𝐺
166
-
𝑦
167
-
2
168
-
value=
169
-
Gx
170
-
2
171
-
+Gy
172
-
2
173
-
151
+
A positive value increases brightness; a negative value decreases it.
152
+
Applied across the image, this produces a uniformly brighter or darker picture.
174
153
154
+
### 7.) The Vignette Algorithm
175
155
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.
156
+
The vignette filter darkens the edges of an image to draw attention toward the center.
177
157
178
-
---
158
+
We compute the distance of each pixel from the image center:
179
159
180
-
### 8.) The Glow Algorithm
160
+
distance = sqrt((x - centerX)² + (y - centerY)²)
181
161
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.
183
162
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:
163
+
Then calculate a scaling factor based on distance:
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.
167
+
168
+
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
+
180
+
181
+
If the result is 128 or greater, the pixel becomes white.
182
+
Otherwise, it becomes black:
183
+
184
+
if avg >= 128 -> (255, 255, 255)
185
+
else -> (0, 0, 0)
186
+
187
+
188
+
This filter produces a strong high-contrast binary image, similar to printed text or stencil art.
189
+
190
+
### 9.) The Edge Detection Algorithm (Sobel Operator)
191
+
192
+
Edge detection highlights boundaries and sharp transitions in an image.
193
+
194
+
We apply the Sobel Kernel in both X and Y directions:
195
+
196
+
Gx = horizontal edge kernel
197
+
Gy = vertical edge kernel
198
+
199
+
200
+
For each pixel, we compute weighted sums for both kernels for each color channel:
201
+
202
+
gradient = sqrt((Gx²) + (Gy²))
203
+
204
+
205
+
The result is then clamped between 0 and 255.
206
+
207
+
Pixels with strong intensity changes become bright (edges), while uniform areas appear dark — producing a clean outline/edge-map of the image.
208
+
209
+
### 10.) The Glow Algorithm
210
+
211
+
Glow enhances bright areas and gives a soft-highlight aura.
0 commit comments