-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmedianFilter.cpp
More file actions
51 lines (51 loc) · 1.3 KB
/
medianFilter.cpp
File metadata and controls
51 lines (51 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//use MinHeap and MaxHeap to get the median value
#include "maxHeap.h"
#include "minHeap.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <stdlib.h>
using namespace std;
void writeImage(vector<int>,string);
void medianFilter(vector<vector<int>>pixel_with_same_index,vector<int>pixel_of_each_file,int size,string header)
{
cout<<"Median Filter is working..."<<endl;
vector<int>medianVector;
int median = 0;
for(int i=0;i<size;i++)
{
//push pixel_with_same_index into heap to calculate the median
MinHeap min;
MaxHeap max;
for(int j=0;j<pixel_with_same_index.size();j++)
{
//accessing the value of 2d vector, means: get the [i]th element from the [j]th vector
int value = pixel_with_same_index[j][i];
min.push(value);
max.push(value);
}
//get the median
while(min.top()!=max.top())
{
min.pop();
max.pop();
}
median = min.top();
// if(min.top()==max.top())
// {
// int median = min.top();
// medianVector.push_back(median);
// }
// else
// {
// cout<<"Data error!"<<endl;
// i=pixel_of_each_file.size();//end the loop
// }
medianVector.push_back(median);
}
cout<<"All images has been processed!"<<endl;
//pass the medianVector to writeImage to get the result image
writeImage(medianVector,header);
}