Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- using namespace std;
- int main(int argc, char* argv[])
- {
- ifstream infile;
- ofstream outfile;
- string feed, type, maxpx, comment;
- int cols, rows;
- const int SIZE = 3;
- infile.open("lena.pgm");
- getline(infile, type);
- infile >> rows >> cols;
- getline(infile, feed);
- getline(infile, maxpx);
- vector<vector<char>> image(rows, vector<char>(cols, '\0'));
- vector<vector<char>> out(rows, vector<char>(cols, '\0'));
- vector<vector<int>> filter = { { 0, -1, 0 }, { -1, 5, -1 }, { 0, -1, 0 } };
- for (int i = 0; i < rows; i++)
- for (int j = 0; j < cols; j++)
- infile >> image[i][j];
- infile.close();
- outfile.open("output.pgm");
- outfile << type << "\n" << comment << "\n" << rows << " " << cols << "\n" << maxpx << "\n";
- for (int i = SIZE / 2; i < rows - SIZE / 2; i++)
- {
- for (int j = SIZE / 2; j < cols - SIZE / 2; j++)
- {
- char sum = '\0';
- for (int k = -SIZE / 2; k <= SIZE / 2; k++)
- {
- for (int l = -SIZE / 2; l <= SIZE / 2; l++)
- {
- sum += image[i+k][j+l] * filter[k + SIZE / 2][l + SIZE / 2];
- }
- }
- out[i][j] = sum;
- }
- }
- for (int i = 0; i < rows; i++)
- for (int j = 0; j < cols; j++)
- outfile << image[i][j];
- outfile.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement