Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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.
- #include<iostream>
- #include<fstream>
- #include<vector>
- #include<map>
- #include<string>
- #include<algorithm>
- using namespace std;
- int median(vector<int> v){ // finds median of a vector
- sort(v.begin(),v.end()); // sort vector to find median
- int mid = (v.size()/2); // median value in the middle
- return v[mid]; // returns value in median index
- }
- int main(int argc,char* argv[]){
- map<int, vector<int> > pictures;
- string name; int width, height, range;
- for(int i = 1; i < argc; i++){ // read in all pictures
- ifstream inStream; inStream.open(argv[i]);
- inStream >> name >> width >> height >> range;
- for(int j = 0; j < width*height*3; j++){
- int num;
- inStream >> num; pictures[i-1].push_back(num);
- }
- inStream.close();
- }
- vector<int> med;
- ofstream outputFile;
- outputFile.open("noPerson.ppm");
- outputFile << name << " " << width << " " << height << " " << range << " ";
- for(int i = 0; i < width*height*3; i++){ // goes through all pixel colours
- for(int j = 0; j < argc-1; j++){ // goes through all pictures
- med.push_back(pictures[j].at(i));
- }
- int chosen = median(med);
- med.clear();
- outputFile << chosen;
- outputFile << " " << endl; // adds space after every median is in-putted
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement