7 Replies - 1442 Views - Last Post: 08 March 2012 - 12:53 PM Rate Topic: -----

#1 hawary  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 08-March 12

how to turn an image into matrix of pixels

Posted 08 March 2012 - 09:21 AM

this code using cimg library but it only for bmp file and i want code that display the matrix
#include "stdafx.h"
#include "CImg-1.5.0_beta\CImg.h"


  using namespace cimg_library;

  int main() {
    CImg<unsigned char> image("Lighthouse.jpg"), visu(500,400,1,3,0);
    const unsigned char red[] = { 255,0,0 }, green[] = { 0,255,0 }, blue[] = { 0,0,255 };
    image.blur(2.5);
    CImgDisplay main_disp(image,"Click a point"), draw_disp(visu,"Intensity profile");
    while (!main_disp.is_closed() && !draw_disp.is_closed()) {
      main_disp.wait();
      if (main_disp.button() && main_disp.mouse_y()>=0) {
        const int y = main_disp.mouse_y();
        visu.fill(0).draw_graph(image.get_crop(0,y,0,0,image.width()-1,y,0,0),red,1,1,0,255,0);
        visu.draw_graph(image.get_crop(0,y,0,1,image.width()-1,y,0,1),green,1,1,0,255,0);
        visu.draw_graph(image.get_crop(0,y,0,2,image.width()-1,y,0,2),blue,1,1,0,255,0).display(draw_disp);
        }
      }
    return 0;
  }



Is This A Good Question/Topic? 0
  • +

Replies To: how to turn an image into matrix of pixels

#2 tlhIn`toq  Icon User is offline

  • Closing in on 5,000
  • member icon

Reputation: 4929
  • View blog
  • Posts: 10,465
  • Joined: 02-June 10

Re: how to turn an image into matrix of pixels

Posted 08 March 2012 - 09:47 AM

What is your goal or intention here? Its not clear, at least to this reader.

An image (bitmap) by its very nature IS a matrix of pixels.

Maybe you have a finished example image... a before and after shot... you could include so we know what you are trying to do?
Was This Post Helpful? 0
  • +
  • -

#3 hawary  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 08-March 12

Re: how to turn an image into matrix of pixels

Posted 08 March 2012 - 09:53 AM

my goal is doing security on images like hiddin water marking so i have to access the pixles of the image
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Closing in on 5,000
  • member icon

Reputation: 4929
  • View blog
  • Posts: 10,465
  • Joined: 02-June 10

Re: how to turn an image into matrix of pixels

Posted 08 March 2012 - 09:59 AM

Ok. But you don't have to *turn* it into anything. A bitmap *is* a matrix of pixels.

So are you saying you need to know how to access a specific pixel?
For example, how do you read the value of a pixel on row 15, column 8?
Was This Post Helpful? 0
  • +
  • -

#5 hawary  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 08-March 12

Re: how to turn an image into matrix of pixels

Posted 08 March 2012 - 10:08 AM

no i want to access it in any image like jpg not the pmb only
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is offline

  • Closing in on 5,000
  • member icon

Reputation: 4929
  • View blog
  • Posts: 10,465
  • Joined: 02-June 10

Re: how to turn an image into matrix of pixels

Posted 08 March 2012 - 10:20 AM

jpgs have rows and columns of pixels. Did you know that?
All image types really come down to the same thing:
A matrix (rows and columns) of pixels.
Each pixel consists of several bytes, most commonly
  • Alpha opacity
  • Red
  • Green
  • Blue

This is known as ARBG. Since there are 4 bytes this is known as 32-bit color (4 * 8 bits per byte)

Jpg images get compressed. Their file structure is not just raw byte data, this is why they are smaller. They will take consecutive bytes of "close enough" value and combine them.
If you have 700 consecutive pixels that would be 700x32bits of data.
Compressed you can have 1 byte for 700 and 1 byte for the value, reducing the size of the final file. That's (simplistically) how image compression works.

It doesn't matter if it is a jpg or a bmp, in the end after decompression you have a matrix of pixels (rows and columns)

You can then scan through them with a couple loops. VERY VERY simplistic representation of that logic would be like this.

for (RowIndex = 0; RowIndex < TotalRows; RowIndex++)
{
   for (ColumnIndex = 0; ColumnIndex < TotalColumns; ColumnIndex++)
   {
      // Do work on pixel located at RowIndex,ColumnIndex
   }
}


Trying to hide data within a jpg becomes increasingly difficult as the level of compression increases. More and more approximate values get normalized to identical values and data hidden can be lost at this point.

There are a lot of libraries and tutorials on the 'net for this. Have you researched them?
Was This Post Helpful? 1
  • +
  • -

#7 hawary  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 08-March 12

Re: how to turn an image into matrix of pixels

Posted 08 March 2012 - 12:33 PM

yes ive researched them like opencv i just have the problem stack over flow when i use the cimg for jpg.. thx
Was This Post Helpful? 0
  • +
  • -

#8 tlhIn`toq  Icon User is offline

  • Closing in on 5,000
  • member icon

Reputation: 4929
  • View blog
  • Posts: 10,465
  • Joined: 02-June 10

Re: how to turn an image into matrix of pixels

Posted 08 March 2012 - 12:53 PM

Stack overflow is almost always caused by your code creating an infinite loop of calls until the stack can no longer track the lineage of all the calls.

I'd bet your problem had more to do with an infinite loop and less to do with what type of file you were trying to employ it on.

What does this error mean? - tutorial
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1