#include <iostream>
#include <vector>
#include <algorithm>
const int WIDTH = 5;
const int HEIGHT = 5;
const int THRESHOLD = 128;
class Image {
public:
Image(const std::vector<std::vector<int>>& pixels) : pixels(pixels) {}
void applyThreshold() {
for (int i = 0; i < HEIGHT; ++i) {
for (int j = 0; j < WIDTH; ++j) {
pixels[i][j] = (pixels[i][j] >= THRESHOLD) ? 255 : 0;
}
}
}
void printImage() const {
for (const auto& row : pixels) {
for (int pixel : row) {
std::cout << (pixel == 255 ? '#' : ' ') << ' ';
}
std::cout << '\n';
}
}
private:
std::vector<std::vector<int>> pixels;
};
int main() {
// Example grayscale image (5x5)
std::vector<std::vector<int>> grayscaleImage = {
{ 10, 50, 150, 200, 250 },
{ 30, 70, 120, 180, 220 },
{ 40, 90, 130, 190, 240 },
{ 60, 100, 140, 170, 210 },
{ 80, 110, 160, 180, 230 }
};
Image image(grayscaleImage);
std::cout << "Original Image:\n";
image.printImage();
image.applyThreshold();
std::cout << "\nThresholded Image:\n";
image.printImage();
return 0;
}