FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   storing images in array ( 'extrusion' example)
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: storing images in array ( 'extrusion' example)  (Read 253 times)
Orkan Telhan
Guest
Email
storing images in array ( 'extrusion' example)
« on: Jan 25th, 2004, 8:25am »

newbie question:
I am trying to store a 2D image in a 2D array.
I have a couple of questions:
 
I was presuming that
img.pixels[] (in Processing)
and
img.getpixels(xy) (in Python) work similar.  
 
I am looking into the 'extrusion' example (under images)
 
  // Load the image into a new array
  // Extract the values and store in an array
  a = loadImage("ystone08.jpg");
  image(a, 0, 0);
  for(int i=0; i<height; i++) {
    for(int j=0; j<width; j++) {
 aPixels[j][i] = a.pixels[i*width + j];
 values[j][i] = int(blue(aPixels[j][i]);
 
and really couldn't get how 'a.pixels' work.
Supposably it should store the color value at the specific position like getpixels in python but when I print its results on the screen, it shows 7 digit numbers like values multiplied with each other.
 
Than values[j][i] is used to extract the blue band of this array (?!)
How come is this possible?
 
Besides then values[j][i] is used to draw points.  
stroke(values[j][i]);
point(j, i, -values[j][i]);
 
What kind of a data is the 2D array in processing holding?
 
Thanks,
 
 
arielm

WWW
Re: storing images in array ( 'extrusion' example)
« Reply #1 on: Jan 25th, 2004, 9:36am »

the pixels array (wether it's the screen's pixels or the pixels of a BImage) is unidimensional, i.e. each pixel is stored serially.
 
there's also the get(int x, int y) method for retrieving a single pixel, which returns:
 
pixels[y * width + x]
 
the point is that this method is slower than working directly with the pixels array.
 
 
concerning the "extrusion" example, it seems that the pixels of an image are transformed to a 2d array for convenience.
 

Ariel Malka | www.chronotext.org
Orkan Telhan
Guest
Email
Re: storing images in array ( 'extrusion' example)
« Reply #2 on: Jan 25th, 2004, 9:51am »


Thanks for the reply.
 
But can you elaborate on this:
 
Why is this again a 2D array?
and when you print the array (aPixels[j][i]) why doesn't it give just RGB values i.e (200, 34, 34) but instead numbers like 6048218 or 9145218?
 
I really couldn't figure out what kind of a data the array is holding?
Thanks,
 
Orkan Telhan
Guest
Email
Re: storing images in array ( 'extrusion' example)
« Reply #3 on: Jan 25th, 2004, 9:55am »


And I guess your answwer will be the array stores the data serially...
 
Is this only a representational difference (I mean does it only show like this) or does it makes a calculation to make them serial? or does it just concatanates the rgb values and show them as a long number?
 
thanks,
 
arielm

WWW
Re: storing images in array ( 'extrusion' example)
« Reply #4 on: Jan 25th, 2004, 12:10pm »

exactly, the rgb values are packed into a single 32 bit number,
 
so, if you convert this number to hexadecimal, you will get something like:
 
00ff8040
 
which equals to a rgb color of (255, 128, 64)
 
note: in this example, only the rightmost 24 bits are used, but sometimes, the 8 leftmost bits can be used to store alpha (transparency) information too.
 
the bottom line: computer graphics algorithms generally are full of code which:
- transforms xy values into a serial index & vice versa
- encodes rgb values into bits & vice versa
 

Ariel Malka | www.chronotext.org
Pages: 1 

« Previous topic | Next topic »