how to display pixel data

This is a discussion on how to display pixel data within the C++ Programming forums, part of the General Programming Boards category; Hi, I have an array of pixel data which i want to display. How should I go by doing this? ...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    14

    how to display pixel data

    Hi,

    I have an array of pixel data which i want to display. How should I go by doing this? The pixel data (an image frame...about 262144 bytes) has a resolution of 512 by 512 displaying at 255 colours.

    Do I have to convert it into a bitmap? I've searched around and people are using opencv. So i gave it a try but with no luck.

    Any help would be really appreciated

    thanks!
    Last edited by vkoo; 07-29-2009 at 10:32 PM.

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    Well you would need some sort of graphics library to actually display it, and based on that graphics library you could simply set some x and y coordinate to your pixel value. It's impossible to answer exactly though without a specified graphics library. If you are on windows GDI will probably be your best bet. For that simply select a compatible bitmap (with the desired dimensions) into your dc and SetPixel() away.

    The other option is to just save the data out as a bitmap file and use a viewer of your choice as you mentioned.

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    14
    ^^ thanks for your advice..i'll look into it

    anyone else? does anyone have experience with openCV?

    right now i have this in openCV:

    Code:
    IplImage* myimage = cvCreateImage(cvSize(width,width), IPL_DEPTH_8S, 1);
    
    			char *data;
    			data = (char*)myimage->imageData;
    
    
    			for(int i = 0; i < width; i++){
    				for(int j = 1; j <= width; j++){
    						data[i*(myimage->widthStep)+j*(myimage->nChannels)] = result_data[counter];
    						counter++;
    				}
    			}
    		
    			counter = 0;
    			cvNamedWindow ("image", CV_WINDOW_AUTOSIZE); 
    			cvShowImage ("image", myimage);
    			cvWaitKey (0);
    			cvReleaseImage (&myimage);
    			cvDestroyWindow("image");
    my result_data contains pixel data of type 8bit signed int (int8_t)

    thanks in advance!
    Last edited by vkoo; 07-30-2009 at 05:28 PM.

  4. #4
    Registered User
    Join Date
    Jul 2009
    Posts
    14
    anybody?

  5. #5
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by vkoo View Post
    anybody?
    Let me google "openvc bmp" for you
    Let me google "IplImage" for you

    Code:
    IplImage* img=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1);
    CvScalar s;
    s=cvGet2D(img,i,j); // get the (i,j) pixel value
    printf("intensity=%f\n",s.val[0]);
    s.val[0]=111;
    cvSet2D(img,i,j,s); // set the (i,j) pixel value
    Code:
          int nl= image->height; // number of lines
    
          int nc= image->width * image->nChannels; // total number of element per line
    
          int step= image->widthStep; // effective width
    
                 
    
          // get the pointer to the image buffer
    
          unsigned char *data= reinterpret_cast<unsigned char *>(image->imageData);
    
     
    
          for (int i=1; i<nl; i++) {
    
                for (int j=0; j<nc; j+= image->nChannels) {
    
     
    
                // process each pixel ---------------------
    
                     
    
                      data[j]= data[j]/div * div + div/2;
    
                      data[j+1]= data[j+1]/div * div + div/2;
    
                      data[j+2]= data[j+2]/div * div + div/2;
    
     
    
                // end of pixel processing ----------------
    
     
    
                } // end of line
    
                       
    
                data+= step;  // next line
    
          }
    Code:
      // load an image  
      img=cvLoadImage(argv[1]);
      if(!img){
        printf("Could not load image file: %s\n",argv[1]);
        exit(0);
      }
    
      // get the image data
      height    = img->height;
      width     = img->width;
      step      = img->widthStep;
      channels  = img->nChannels;
      data      = (uchar *)img->imageData;
      printf("Processing a %dx%d image with %d channels\n",height,width,channels); 
    
      // create a window
      cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); 
      cvMoveWindow("mainWin", 100, 100);
    
      // invert the image
      for(i=0;i<height;i++) for(j=0;j<width;j++) for(k=0;k<channels;k++)
        data[i*step+j*channels+k]=255-data[i*step+j*channels+k];
    
      // show the image
      cvShowImage("mainWin", img );
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    137
    On which OS ?
    On Windows, simply use GDI. It's automatic.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 11:13 AM
  2. Replies: 48
    Last Post: 09-26-2008, 04:45 AM
  3. Reading pixel color data from screen
    By JJFMJR in forum Windows Programming
    Replies: 8
    Last Post: 08-22-2008, 01:27 PM
  4. Read pixel color data from screen?
    By JJFMJR in forum Windows Programming
    Replies: 4
    Last Post: 08-11-2008, 11:15 AM
  5. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 08:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21