histogram.pde
来自「This is processing for java examples.」· PDE 代码 · 共 47 行
PDE
47 行
/** * 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. */ size(200, 200);colorMode(RGB, width);int[] hist = new int[width];// Load an image from the data directory// Load a different image by modifying the commentsPImage a;a = loadImage("cdi01_g.jpg");image(a, 0, 0);// Calculate the histogramfor (int i=0; i<width; i++) { for (int j=0; j<height; j++) { hist[int(red(get(i, j)))]++; }} // Find the largest value in the histogramfloat maxval = 0;for (int i=0; i<width; i++) { if(hist[i] > maxval) { maxval = hist[i]; } }// Normalize the histogram to values between 0 and "height"for (int i=0; i<width; i++) { hist[i] = int(hist[i]/maxval * height);}// Draw half of the histogram (skip every second value)stroke(width);for (int i=0; i<width; i+=2) { line(i, height, i, height-hist[i]);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?