Hey guys

Im currently working on an individual mini project for my univeristy. My assignment is to create a program that converts an RGB image to an HSI image.
So i believe that what i have to do is:

-Load a color image into my program
-Somehow convert them to HSI

I have already loaded the picture into my program using this code:

void testApp::setup(){
x = (ofGetWidth() - testImg.getWidth()) / 2;
y = (ofGetHeight() - testImg.getHeight()) / 2;

colorImg.allocate(testImg.getWidth(), testImg.getHeight());
colorImg.setFromPixels(testImg.getPixels(), testImg.getWidth(), testImg.getHeight());
grayImg.allocate(testImg.getWidth(), testImg.getHeight());
grayImg = colorImg;

And this is how i get it to be in color:

void testApp::draw(){
//testImg.draw(x, y);
colorImg.draw(x, y);
//grayImg.draw(x,y);

However i simply cannot figure out how to read the RGB values. Maybe if i use the getpixels function, but i simply cannot figure out how to implement it properly. Sorry if i sound like a total n00b, but the simple fact is, i am. Programming is not one of my strong points, but passing the mini project is required in order to even participate in the exams next january, so it is quite important for me.

Regards Las88

Hi,

The OF wiki page may have wath you need, if you check the Vector Field section http://wiki.openframeworks.cc/index.php?title=Making-VectorFields-from-images the “The Algorithm” part have a piece of code to read all pixels from an image, but they convert the image to black and white first, anyway check it out and post any questions.

Hope that helps!

rS

Hey,

i think i may be able to help.

``````

//THEN GET PIXEL VALUES
unsigned char * pixelValues=testImg.getPixels();

//NOW YOU HAVE PIXELS YOU CAN ALTER THEM AS YOU LIKE
//FOR EXAMPLE:

for( int i = 0; i < testImg.width*testImg.height ;i++)
{
pixelValues[ i*3 ]; //R
pixelValues[ i*3+1 ]; //G
pixelValues[ i*3+2 ]; //B
}

testImg.setFromPixels(pixelValues, testImg.width,testImg.height,OF_IMAGE_COLOR);

``````

Note that if you have alpha in image the code would be different:

``````

for( int i = 0; i < testImg.width*testImg.height ;i++)
{
pixelValues[ i*4 ]; //R
pixelValues[ i*4+1 ]; //G
pixelValues[ i*4+2 ]; //B
pixelValues[ i*4+3 ]; //B
}

``````