#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;
}
how to turn an image into matrix of pixels
Page 1 of 17 Replies - 1442 Views - Last Post: 08 March 2012 - 12:53 PM
#1
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
Replies To: how to turn an image into matrix of pixels
#2
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?
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?
#3
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
#4
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?
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?
#5
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
#6
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
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.
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?
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?
#7
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
#8
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
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
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|