Skip to content

Commit 91723a7

Browse files
committed
feat: readme updating
1 parent ac08fb0 commit 91723a7

File tree

2 files changed

+185
-60
lines changed

2 files changed

+185
-60
lines changed

README.md

Lines changed: 184 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -113,81 +113,138 @@ For a pixel along the edge or corner, like pixel 15, we would still look for all
113113

114114
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.
115115

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:
164+
165+
vignetteStrength = 1 - (distance / maximumDistance)
166+
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+
124180

125-
### 6.) The Threshold Algorithm
181+
If the result is 128 or greater, the pixel becomes white.
182+
Otherwise, it becomes black:
126183

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)
128186

129-
For each pixel, the intensity is calculated as the average of its red, green, and blue values:
130187

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.
134189

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)
137191

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.
139193

194+
We apply the Sobel Kernel in both X and Y directions:
140195

141-
### 7.) The Edge Detection (Sobel) Algorithm
196+
Gx = horizontal edge kernel
197+
Gy = vertical edge kernel
142198

143-
The “edge detection” filter highlights sharp changes in pixel intensity, producing a sketch-like outline of the image.
144199

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:
146201

147-
Horizontal (Gx):
148-
-1 0 1
149-
-2 0 2
150-
-1 0 1
202+
gradient = sqrt((Gx²) + (Gy²))
151203

152-
Vertical (Gy):
153-
-1 -2 -1
154-
0 0 0
155-
1 2 1
156204

157-
The gradient magnitude for each color channel is then computed as:
205+
The result is then clamped between 0 and 255.
158206

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.
174208

209+
### 10.) The Glow Algorithm
175210

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.
177212

178-
---
213+
Steps:
179214

180-
### 8.) The Glow Algorithm
215+
Make a copy of the original image
181216

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
183218

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:
219+
Blend the blurred and original pixels:
185220

186-
- `finalRed = 0.7 * originalRed + 0.3 * blurredRed`
187-
- `finalGreen = 0.7 * originalGreen + 0.3 * blurredGreen`
188-
- `finalBlue = 0.7 * originalBlue + 0.3 * blurredBlue`
221+
newPixel = (1 - blend) * original + blend * blurred
189222

190-
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.
191248

192249
### Usage
193250

@@ -202,14 +259,84 @@ To apply a filter via command-line:
202259
- `t`: threshold
203260
- `d`: edge detection
204261
- `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).
205282

206-
Example for glow:
207-
./filter -G input.bmp output.bmp
283+
## Supported Image Formats
208284

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.
294+
295+
### Examples with Different Formats
296+
297+
```bash
298+
# Process PNG image
299+
./filter.exe -g photo.png photo_gray.png
300+
# Process JPEG image
301+
./filter.exe -s photo.jpg photo_sepia.jpg
302+
# Convert PNG to JPEG
303+
./filter.exe -g input.png output.jpg
304+
# Convert JPEG to BMP
305+
./filter.exe -b input.jpg output.bmp
306+
# Chain filters on PNG
307+
./filter.exe -g -b input.png output.png
210308
```
211-
./filter v input.bmp output.bmp
309+
310+
## Building and Installation
311+
312+
#### Windows (MSYS2)
313+
```bash
314+
# Install dependencies in MSYS2 UCRT64 terminal
315+
pacman -Syu
316+
pacman -S mingw-w64-ucrt-x86_64-gcc
317+
pacman -S mingw-w64-ucrt-x86_64-libpng
318+
pacman -S mingw-w64-ucrt-x86_64-libjpeg-turbo
319+
pacman -S make
212320
```
321+
322+
#### Linux (Ubuntu/Debian)
323+
```bash
324+
sudo apt-get update
325+
sudo apt-get install libpng-dev libjpeg-dev build-essential
326+
```
327+
328+
#### macOS
329+
```bash
330+
brew install libpng libjpeg
331+
```
332+
333+
### Building
334+
335+
```bash
336+
make clean
337+
make
338+
```
339+
213340
You can also chain multiple filters by supplying multiple tags (e.g., `./filter vg input.bmp output.bmp` for vignette then grayscale).
214341

215342
You should not modify any of the function signatures, nor should you modify any other files other than helpers.c.

filter.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,9 @@ int main(int argc, char *argv[])
123123
break;
124124

125125
// Brightness Adjust
126-
case 'B': {
127-
int brightness_value = atoi(optarg);
126+
case 'B':
128127
brightness(height, width, image, brightness_value);
129128
break;
130-
}
131129
case 'G':
132130
glow(height, width, image);
133131
break;

0 commit comments

Comments
 (0)