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 line, type, maxpx, comment;
- int cols, rows;
- const int SIZE = 3;
- infile.open("/Users/dotun/Desktop/file/file/lena.pgm", ios::binary);
- getline(infile, type); //Read first line and grab the type of file
- //getline(infile, comment); //Read second line and discard it
- infile >> rows >> cols; //Read third line and get columns and rows
- getline(infile, line);
- getline(infile, maxpx); //Read highest pixel
- 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 } }; //Sharpen
- for (int i = 0; i < rows; i++)
- for (int j = 0; j < cols; j++)
- infile >> image[i][j];
- infile.close();
- outfile.open("/Users/dotun/Desktop/file/file/output.pgm", ios::binary);
- 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