How to move the histogram at different coordinates


I've followed the instructions in the histogram example but I get into trouble when I want to move the histogram to different coordinates, here's the script I've created in accordance with the histogram example that's on the processing page :

PImage object;





int [] hist = new int[256];

for (int i = 0; i< object.width; i++){

for (int j = 0; j< object.height; j++){

int bright = int (brightness(get(i,j)));




int histMax = max(hist);


for (int i = 0; i< object.width; i +=2){

int which = int(map(i,0, object.width,0,255));

int y = int (map(hist[which], 0, histMax,object.height,0));




  • Edit your post (gear icon in the top right corner of your post), select your code and hit ctrl+o to format your code. Make sure there is an empty line above and below your code.

    You have to change the values of i when you call line() in the last function.

    Your sketch is defined as size(1000,500);

    We don't know anything about your image's original size. However, we can constrained it to use only half of the sketch's surface: object.resize(500,0); which could be improved by calling object.resize(width/2,0); instead. Please check the reference related to the resize() functionality.

    Now what you can do:

    line(i+width/2, object.height, i+width/2, y); //Introduce an X offset for your hist


  • fix

    The line () function at the end I have created with what you have instructed, and the result is successful My original image is 500x500 pixel then I made 1000,500 size Thanks kfrajer for always being present and answering any questions from me

  • Answer ✓

    You are very welcome. Please don't forget to edit your post and format your code. This will help other forum-goers.


  • Of course sir, thanks for the help

Sign In or Register to comment.