# How to make histogram but the PImage location is not 0, 0

**URL:** <https://discourse.processing.org/t/how-to-make-histogram-but-the-pimage-location-is-not-0-0/33742>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [November 25, 2021, 3:06am UTC](https://discourse.processing.org/t/how-to-make-histogram-but-the-pimage-location-is-not-0-0/33742 "2021-11-25T03:06:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RNWA](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@RNWA](https://discourse.processing.org/u/RNWA)\
**Post date:** [November 25, 2021, 3:06am UTC](https://discourse.processing.org/t/how-to-make-histogram-but-the-pimage-location-is-not-0-0/33742/1 "2021-11-25T03:06:01Z")

</div>

Hi, im a beginner in processing and tried to make histogram from PImage but the location i want to start it for example 200, 100. I tried play around with it and i got nothing, so pls any help i really appreciate it, and here’s the code

```auto
/**
 * Histogram. 
 * 
 * Calculates the histogram of an image. 
 * A histogram is the frequency distribution 
 * of the gray levels with the number of pure black values
 * displayed on the left and number of pure white values on the right. 
 *
 * Note that this sketch will behave differently on Android, 
 * since most images will no longer be full 24-bit color.
 */

size(640, 360);

// Load an image from the data directory
// Load a different image by modifying the comments
PImage img = loadImage("frontier.jpg");
image(img, 200, 100);
int[] hist = new int[256];

// Calculate the histogram
for (int i = 0; i < img.width; i++) {
  for (int j = 0; j < img.height; j++) {
    int bright = int(brightness(get(i, j)));
    hist[bright]++; 
  }
}

// Find the largest value in the histogram
int histMax = max(hist);

stroke(255);
// Draw half of the histogram (skip every second value)
for (int i = 0; i < img.width; i += 2) {
  // Map i (from 0..img.width) to a location in the histogram (0..255)
  int which = int(map(i, 0, img.width, 0, 255));
  // Convert the histogram value to a location between 
  // the bottom and the top of the picture
  int y = int(map(hist[which], 0, histMax, img.height, 0));
  line(i, img.height, i, y);
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [November 25, 2021, 12:06pm UTC](https://discourse.processing.org/t/how-to-make-histogram-but-the-pimage-location-is-not-0-0/33742/2 "2021-11-25T12:06:56Z")

</div>

Hello,

There are tutorials, examples and references here:

> **[Welcome to Processing!](https://processing.org)**
>
> Processing is a flexible software sketchbook and a language for learning how to code. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology…

I saw a good example in there of processing a portion of an image that may help.

There are also examples that come with the Processing IDE.

There is an example here where I get() a portion of an image and work with it:

> [@Filling a PShape](https://discourse.processing.org/t/filling-a-pshape/33644/2):
>
> Hello, Here is an example using the existing circle() shape: PImage img1, img2; PGraphics pg; void setup() { size(300, 300); //img1 = loadImage("https://processing.org/img/processing-web.png"); img1 = loadImage("https://raw.githubusercontent.com/processing/processing-website/main/content/examples/Basics/Image/LoadDisplayImage/data/moonwalk.jpg"); img2 = createImage(100, 100, RGB); img2 = img1.get(360, 100, 100, 100); pg = createGraphics(100, 100); pg.beginDraw(); //pg.…

`:)`
