Search⌘ K

Solution: Mini Project 1

Discover how to process grayscale images in C++ by applying thresholding techniques to convert them into black and white. Learn to navigate 2D arrays using nested loops and understand pixel value manipulation to create image effects. This lesson guides you through a practical mini project solution, helping you apply concepts related to image processing and interactive coding in C++.

We'll cover the following...

Solution #

Press the RUN button and see the output!

C++
#include "imagelib.h"
int main() {
// Displays input image
loadFile("input.png");
// Traverse rows in 2D array
for (int i = 0; i < height; i++) {
// Traverse columns in each row
for (int j = 0; j < width; j++) {
// Process pixel image[i][j], here
if (image[i][j] <= 70) {
// Sets image pixel to black
image[i][j] = 0;
} else {
// Sets image pixel to white
image[i][j] = 255;
}
}
}
// Displays modified image
saveFile("output/modified.png");
}

📝Note: In the above code widget, you can see the modified image by pressing the arrow button > towards the right of ...