Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to get pixel's value from a RGB picture

Hi guys,

I intend to get the pixel value from a picture, but I don't know how to do that, can someone help me please?

I have already loaded and resized an image, now I would like to get the pixel value from the new image and print it, probably I will need to use Matrices, but I don't know how. I would like to get the RGB pixel value and differentiate it in a matrix for each color ( Red, Green and Blue).

I would appreciate it if someone could help me with a sample code.

My code to load and resize the image is that:

#include <opencv\cv.h>
#include <opencv\highgui.h>

int main()
{
    cvNamedWindow( "original", CV_WINDOW_AUTOSIZE );
    cvNamedWindow( "new", CV_WINDOW_AUTOSIZE );

    IplImage* img = cvLoadImage("Koala.jpg");
    cvShowImage("original:",img);

    CvSize size = cvSize(800, 600); 
    IplImage* tmpsize=cvCreateImage(size, img->depth, img->nChannels); 

    cvResize(img,tmpsize,CV_INTER_LINEAR);
    cvShowImage("new",tmpsize);

    cvWaitKey(0);
    return 0;
}

Thank you, Jack.

How to get pixel's value from a RGB picturepicture?

Hi guys,

I intend to get the pixel value from a picture, but I don't know how to do that, can someone help me please?

I have already loaded and resized an image, now I would like to get the pixel value from the new image and print it, probably I will need to use Matrices, but I don't know how. I would like to get the RGB pixel value and differentiate it in a matrix for each color ( Red, Green and Blue).

I would appreciate it if someone could help me with a sample code.

My code to load and resize the image is that:

#include <opencv\cv.h>
#include <opencv\highgui.h>

int main()
{
    cvNamedWindow( "original", CV_WINDOW_AUTOSIZE );
    cvNamedWindow( "new", CV_WINDOW_AUTOSIZE );

    IplImage* img = cvLoadImage("Koala.jpg");
    cvShowImage("original:",img);

    CvSize size = cvSize(800, 600); 
    IplImage* tmpsize=cvCreateImage(size, img->depth, img->nChannels); 

    cvResize(img,tmpsize,CV_INTER_LINEAR);
    cvShowImage("new",tmpsize);

    cvWaitKey(0);
    return 0;
}

Thank you, Jack.