Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ The vignette filter gives an image a cinematic look by gradually darkening its c

If you apply this algorithm, your resulting image will have gently darkened corners and an undisturbed/sunnier center.

### 6.) The Threshold Algorithm

The “threshold” filter converts a colorful image into a pure black-and-white one based on pixel intensity.

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

\[
\text{intensity} = \frac{(R + G + B)}{3}
\]

If the intensity is **greater than or equal to 128**, the pixel is set to **white** (`R = G = B = 255`).
Otherwise, it is set to **black** (`R = G = B = 0`).

This results in a high-contrast, two-tone image where all intermediate shades are eliminated — essentially a hard binary “black-and-white” conversion.


---

### Usage
Expand Down
5 changes: 4 additions & 1 deletion filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
int main(int argc, char *argv[])
{
// Define allowable filters
char *filters = "bgrsiv";
char *filters = "bgrsivt";


char filterArr[argc-3];
Expand Down Expand Up @@ -128,6 +128,9 @@ int main(int argc, char *argv[])
case 'v':
vignette(height, width, image);
break;
case 't':
threshold(height, width, image);
break;
default:
printf("%c", &filterArr[i]);
break;
Expand Down
27 changes: 27 additions & 0 deletions helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,30 @@ void vignette(int height, int width, RGBTRIPLE image[height][width]){
}
}
}

//Threshold Filter(Black & White)
void threshold(int height, int width, RGBTRIPLE image[height][width])
{
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
int avg = round((image[i][j].rgbtRed +
image[i][j].rgbtGreen +
image[i][j].rgbtBlue) / 3.0);

if (avg >= 128)
{
image[i][j].rgbtRed = 255;
image[i][j].rgbtGreen = 255;
image[i][j].rgbtBlue = 255;
}
else
{
image[i][j].rgbtRed = 0;
image[i][j].rgbtGreen = 0;
image[i][j].rgbtBlue = 0;
}
}
}
}
5 changes: 4 additions & 1 deletion helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ void reflect(int height, int width, RGBTRIPLE image[height][width]);
// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width]);
// Vignette image
void vignette(int height, int width, RGBTRIPLE image[height][width]);
void vignette(int height, int width, RGBTRIPLE image[height][width]);

//Threshold Filter(Black & White)
void threshold(int height, int width, RGBTRIPLE image[height][width]);
Loading