# Re-scaling image by pixel: why is r NaN?

**URL:** https://discourse.processing.org/t/re-scaling-image-by-pixel-why-is-r-nan/19008
**Category:** Beginners
**Created:** [March 25, 2020, 4:27pm UTC](https://discourse.processing.org/t/re-scaling-image-by-pixel-why-is-r-nan/19008 "2020-03-25T16:27:44Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![casey123](https://avatars.discourse-cdn.com/v4/letter/c/57b2e6/32.png) [@casey123](https://discourse.processing.org/u/casey123)
#### Post date: [March 25, 2020, 4:27pm UTC](https://discourse.processing.org/t/re-scaling-image-by-pixel-why-is-r-nan/19008/1 "2020-03-25T16:27:44Z")

</div>

I want to eventually re-scale my imported image while skewing it. Right now, I’m trying to get per pixel info but my variable “r” here is undefined in console. What am I missing? Thanks

```auto
var img;
var vScale = 4;

function preload(){
   
       img = loadImage('image.jpeg');   
       }

function setup() {
    createCanvas(500, 550);
    pixelDensity(1);
    background(51);

    image(img, width/2- 200, height-300, 400, 300);
    
}

function draw(){
   

    loadPixels();
    
    //cycle through the loop of pixels per row
    for(var y = 0; y < img.height; y++){
       for (var x = 0; x < img.width; x++){
           //find the pixels: every pixel has 4 values
                var index = (x + y * img.width) * 4;
                   
                   var r = img.pixels[index+0];
                   var g = img.pixels[index+1];
                   var b = img.pixels[index+2];

                   console.log(r);
          
     }
    }
    

    
   // updatePixels();
    
    
}

```

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [March 25, 2020, 9:55pm UTC](https://discourse.processing.org/t/re-scaling-image-by-pixel-why-is-r-nan/19008/2 "2020-03-25T21:55:53Z")

</div>

> [@casey123](#):
>
> What am I missing?

Perhaps you miss a call to method p5.Image::**loadPixels()** before accessing p5.Image::_pixels[]_: `img.loadPixels();`

> **[reference | p5.js](https://p5js.org/reference/#/p5.Image/loadPixels)**
>
> p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.

> **[reference | p5.js](https://p5js.org/reference/#/p5.Image/pixels)**
>
> p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.
