convertir vectors to images

hi, im very new with openframeworks im trying to make an old program i did before with processing in of.
The program works in this way, the program iterates over all the pixels of an image and create 3 news vectors or arrays based in its luminosty. My question is : which is the best way to converting back a vector into a image? if this is not possible which is the best way to draw a vector as an image?

here is an example of the code:
the 3 vectos are: oscuros, medios and claros, thanks

  
  
void testApp::keyPressed  (int key){  
    if (key = 358){  
        unsigned char * pixels = img.getPixels();  
        int w = img.width;  
        int h = img.height;  
  
        vector<int> claros;  
        vector<int> medios;  
        vector<int> oscuros;  
  
        for (int i = 0; i < w; i++){  
            for (int j = 0; j < h; j++){  
                int value = pixels[j * w + i];  
                //cout << value << endl;  
                if (value >= 0 && value <= 50)  
                    oscuros.push_back(value);  
                else if (value >= 51 && value <= 101)  
                    medios.push_back(value);  
                else  
                    claros.push_back(value);  
            }  
        }  
    //cout < claros.  
  
    }  
}  
  
  
  

you could always render your vectors on screen and then save the result to an ofImage. This would look a little like this (taken from the ofSaveScreen function):

  
  
        ofImage img;  
	img.allocate(ofGetWidth(), ofGetHeight(), OF_IMAGE_COLOR);  
	img.grabScreen(0, 0, ofGetWidth(), ofGetHeight());  
  

greets ph

thanks but how do i render the vectors with pixel data in the screen?

thanks

You can only do it manually with a series of ofLine(x1, y1, x2, y2) commands.

g.ph

indeed a vector is internally just an array, so you can load it’s contents to a texture. it dependes on how you want to actually render it but let’s say you want to render it’s contents as a line:

  
  
.h  
ofTexture tex  
  
.cpp  
  
update(){  
...  
tex.allocate(claros.size(),1,GL_LUMINANCE);  
tex.loadPixels(&claros[0],claros.size(),1,GL_LUMINANCE);  
...  
}  
  
draw(){  
tex.draw();  
}