# Working with PImages in a 2D-array

**URL:** <https://discourse.processing.org/t/working-with-pimages-in-a-2d-array/12099>\
**Category:** Coding Questions\
**Created:** [June 16, 2019, 4:42pm UTC](https://discourse.processing.org/t/working-with-pimages-in-a-2d-array/12099 "2019-06-16T16:42:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TTG](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ttg/32/983_2.png) [@TTG](https://discourse.processing.org/u/TTG)\
**Post date:** [June 16, 2019, 4:42pm UTC](https://discourse.processing.org/t/working-with-pimages-in-a-2d-array/12099/1 "2019-06-16T16:42:37Z")

</div>

Hi team.  
I have images in a 2d-array. each image is representing a colored image and acts as a timestamp having the colors representing a value  
The images contain 12 months and for each month 16 hrs ( 2D-array= [12][16]);

to display the pictures it goes well and fast once in draw mode ( loading takes 12 secs though).

```auto
    for (int t=1; t<12; t++){
          for (int m=6; m<22;m++){
            editImage=loadImage(dataPath("\\pic_solar\\dirdiff\\dirdiff_"+ t+m + ".png"));
            solarData[t-1][m-6]= editImage.get(77,30,1138,844); //Get a portion of the loaded image with 
              }
                 }

```

Though i am aiming to do simple subtraction or addition to for instance have an annual outcome.  
Accessing the data is harder as initially thought.  
Initially i thinked this would be faster as bringing .csv data in (becomes quite large) so started to import the data as color images. Having in mind I would add or subtract the r,g,b, integers per pixel afterwards in a separate array. it seems that might be wrong with this approach as it results in many nested loops (accessing a 2-d array for the image itself and then two to access each pixel ).

Does any of you can point me out it is indeed a wrong approach or that i miss an essential step. It could be that PImage file formats can be added (i saw a blendmode) , then having to only map the rgb data so it stays within 0-255. Hoping having the data ready in a 2d-Array as now can lead to a timefriendly operation.

---

<div class="post-metadata">

**Author:** ![TTG](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ttg/32/983_2.png) [@TTG](https://discourse.processing.org/u/TTG)\
**Post date:** [June 17, 2019, 1:38pm UTC](https://discourse.processing.org/t/working-with-pimages-in-a-2d-array/12099/2 "2019-06-17T13:38:37Z")

</div>

update:  
added the loadPixels(). to have the data available

```auto
  solar1[0].loadPixels(); // pushes the data in a special array
  for (int x = 0; x < 2200; x++ ) {
    for (int y = 0; y < 900; y++ ) {
      int loc = x + y * 2200;
      // What is current color
      color currentColor = solar1[0].pixels[loc];

```

Not looping over the 2d array yet, but hoping it is a step in the good direction
