<< Chapter < Page Chapter >> Page >

Modify the Processing code of [link] in order to add the operation of equalization of the histogram.

int grayValues = 256; int[]hist = new int[grayValues];int[] histc = new int[grayValues]; PImage a;void setup() { background(255);stroke(0,0,0); size(300, 420);colorMode(RGB, width); framerate(5);a = loadImage("lena.jpg"); image(a, 0, 0);} void draw() {// calculate the histogram for (int i=0; i<width; i++) { for (int j=0; j<height; j++) { int c = constrain(int(red(get(i,j))), 0, grayValues-1);hist[c]++;} }// Find the largest value in the histogram float maxval = 0; for (int i=0; i<grayValues; i++) { if(hist[i]>maxval) { maxval = hist[i]; }} // Accumulate the histogramhistc[0] = hist[0]; for (int i=1; i<grayValues; i++) { histc[i]= histc[i-1] + hist[i]; }// Normalize the histogram to values between 0 and "height"for (int i=0; i<grayValues; i++) { hist[i]= int(hist[i]/maxval * height);} if (mousePressed == true) { //equalizationfor (int i=1; i<grayValues; i++) { println(float(histc[i])/histc[grayValues-1]*256);} loadPixels();println("click"); for (int i=0; i<width; i++) for (int j=0; j<height; j++) { //normalized cumulated histogram mappingpixels[i+j*width] = color(int( float(histc[constrain(int(red(a.get(i,j))), 0, grayValues-1)])/ histc[grayValues-1]*256)); }updatePixels(); }// Draw half of the histogramstroke(50, 250, 0); strokeWeight(2);for (int i=0; i<grayValues; i++) { line(i, height, i, height-hist[i]); }}

Got questions? Get instant answers now!

Segmentation and contour extraction

Contours

The objects that populate a scene represented in an image are usually detectable by means of their contours:Thread-like profiles that correspond to a fast variation of color or of gray intensity. The contour extraction is one of the typicaloperation of the image processing. From the point of view of the Mathematical Analysis, a fast variation of a function corresponds to a high value of the derivative function. In the frame of Digital Signal Processing (DSP), the derivative can be approximated by means of a difference operation, i.e.by means of a filter. The filters that let fast variations through and eliminate slowvariations are of a high-pass type. It is not surprising, thus, that for contour extraction, one uses convolution masks similar to that seenin Elementary Filters employed for edge crispening. More in detail, one can say that in 2D one looks for points with maximum amplitude of the gradient , i.e. points, where the Laplacian of the image that is its second spatial derivative is necessarily zero.The Laplacian can be approximated (in the discrete space) by means of a convolution mask 0 1 0 1 -4 1 0 1 0 . The direct application of the Laplacian is often not satisfying, since the result is too sensitive to noise and to small details.It is, thus, useful to combine the Laplacian mask with that of a low-pass filter. The combination of a Laplacian and a Gaussian ( LoG ) filter produces, in the case 5 by 5 , the mask 0 0 -1 0 0 0 -1 -2 -1 0 -1 -2 16 -2 -1 0 -1 -2 -1 0 0 0 -1 0 0 In the software Gimp, a contour enhancer is available, based on the difference between two Gaussian filters, corresponding to two Gaussian curveswith different amplitude. This produces an inhibition effect outside the principal contours, in a way similar to what happens in our perceptual system.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Media processing in processing. OpenStax CNX. Nov 10, 2010 Download for free at http://cnx.org/content/col10268/1.14
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Media processing in processing' conversation and receive update notifications?

Ask