Advertisement
KillianMills

filter.cpp

Oct 24th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. // This program takes in a series of images taken of the same person/place/thing and filters out any inconsistencies that occur, using this I removed the images of a man walking in front of a piece of art and was left with just a picture of the artwork, see pesky tourist assignment.
  2.  
  3. #include<iostream>
  4. #include<fstream>
  5. #include<vector>
  6. #include<map>
  7. #include<string>
  8. #include<algorithm>
  9.  
  10. using namespace std;
  11.  
  12. int median(vector<int> v){ // finds median of a vector
  13.     sort(v.begin(),v.end()); // sort vector to find median
  14.     int mid = (v.size()/2); // median value in the middle
  15.     return v[mid]; // returns value in median index
  16. }
  17.  
  18. int main(int argc,char* argv[]){
  19.     map<int, vector<int> > pictures;
  20.     string name; int width, height, range;
  21.      
  22.     for(int i = 1; i < argc; i++){ // read in all pictures
  23.      
  24.         ifstream inStream; inStream.open(argv[i]);
  25.         inStream >> name >> width >> height >> range;
  26.         for(int j = 0; j < width*height*3; j++){
  27.          
  28.             int num;
  29.             inStream >> num; pictures[i-1].push_back(num);
  30.         }
  31.         inStream.close();
  32.     }
  33.    
  34.     vector<int> med;
  35.     ofstream outputFile;
  36.     outputFile.open("noPerson.ppm");
  37.     outputFile << name << " " << width << " " << height << " " << range << " ";
  38.    
  39.     for(int i = 0; i < width*height*3; i++){ // goes through all pixel colours
  40.    
  41.         for(int j = 0; j < argc-1; j++){ // goes through all pictures
  42.            
  43.             med.push_back(pictures[j].at(i));
  44.         }
  45.         int chosen = median(med);
  46.         med.clear();
  47.         outputFile << chosen;
  48.         outputFile << " " << endl; // adds space after every median is in-putted
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement