Last active
March 16, 2018 14:02
-
-
Save gcorallo/043b3c91cbb50b0dd0de1789d88a8c7c to your computer and use it in GitHub Desktop.
almost median filter.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
//-------------------------------------------------------------- | |
void ofApp::setup(){ | |
img.load("img.jpg"); | |
pix = img.getPixels(); | |
pix2 = img.getPixels(); | |
ind =0; | |
doExport=true; | |
} | |
//-------------------------------------------------------------- | |
void ofApp::update(){ | |
pix = img.getPixels(); | |
for(int i=1; i<img.getWidth()-1; i++){ | |
for(int j=1; j<img.getHeight()-1;j++){ | |
float x=i; | |
float y=j; | |
std::list<ofColor> colors; | |
colors.sort([](const ofColor &f, const ofColor &s) { return f.b < s.b; }); | |
ofColor c0 = pix.getColor(x-1,y-1); | |
colors.push_back(c0); | |
ofColor c1 = pix.getColor(x,y-1); | |
colors.push_back(c1); | |
ofColor c2 = pix.getColor(x+1,y-1); | |
colors.push_back(c2); | |
ofColor c3 = pix.getColor(x-1,y); | |
colors.push_back(c3); | |
ofColor c4 = pix.getColor(x,y); | |
colors.push_back(c4); | |
ofColor c5 = pix.getColor(x+1,y); | |
colors.push_back(c5); | |
ofColor c6 = pix.getColor(x-1,y+1); | |
colors.push_back(c6); | |
ofColor c7 = pix.getColor(x,y+1); | |
colors.push_back(c7); | |
ofColor c8 = pix.getColor(x+1,y+1); | |
colors.push_back(c8); | |
colors.sort([](const ofColor &f, const ofColor &s) { return f.getHue() < s.getHue(); }); | |
pix2.setColor(x,y, getColor(colors, 3)); | |
} | |
} | |
if(doExport && ofGetFrameNum()<500){ | |
ostringstream st; | |
st << "frame_" << setw(5) << setfill('0') << ofGetFrameNum() << ".png"; | |
string fn = "./exp4/"+st.str(); | |
ofSaveImage(pix2, fn); | |
cout<<"saved frame: "<<ofGetFrameNum()<<endl; | |
} | |
} | |
//-------------------------------------------------------------- | |
void ofApp::draw(){ | |
img.setFromPixels(pix2); | |
img.draw(0,0); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::keyPressed(int key){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::keyReleased(int key){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseMoved(int x, int y ){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseDragged(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mousePressed(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseReleased(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseEntered(int x, int y){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseExited(int x, int y){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::windowResized(int w, int h){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::gotMessage(ofMessage msg){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::dragEvent(ofDragInfo dragInfo){ | |
} | |
ofColor ofApp::getColor(list<ofColor> _list, int _i){ | |
list<ofColor>::iterator it = _list.begin(); | |
for(int i=0; i<_i; i++){ | |
++it; | |
} | |
return *it; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment