<< Chapter < Page Chapter >> Page >
Miscellaneous topics and effects in audio and image processing.

Economic color representations

In Media Representation in Processing we saw how one devotes 8 bits to each channel corresponding to a primary color. If we add to these the alpha channel, the total number of bits per pixel becomes 32 . We do not always have the possibility to use such a big amount of memory for colors. Therefore, one has to adopt various strategies in order to reduce the number of bits per pixel.

Palette

A first solution comes from the observation that usually in an image, not all of the 2 24 representable colors are present at the same time. Supposing that the number of colors necessary for an ordinary image is not greater than 256 , one can think about memorizing the codes of the colors in a table( palette ), whose elements are accessible by means of an index of only 8 bits. Thus, the image will require a memory space of 8 bits per pixel plus the space necessary for the palette. For examples and further explanations see color depth in Wikipedia.

Dithering

Alternatively, in order to have a low number of bits per pixel, one can apply a digital processing technique called dithering . The idea is that of obtaining a mixture of colors in a perceptual way, exploiting the proximity of small points of different color. An exhaustivepresentation of the phenomenon can be found at the voice dithering of Wikipedia.

Floyd-steinberg's dithering

The Floyd-Steinberg's algorithm is one of the most popular techniques for the distribution of colored pixels in order to obtain adithering effect. The idea is to minimize the visual artifacts by processing the error-diffusion. The algorithm can be resumedas follows:

  • While proceeding top down and from left to right for each considered pixel,
    • calculate the difference between the goal color and the closest representable color (error)
    • spread the error on the contiguous pixels according to the mask 1 16 0 0 0 0 X 7 3 5 1 . That is, add 7 16 of the error to the pixel on the right of the considered one, add 3 16 of the error to the pixel bottom left with respect to the considered one, and so on.
By means of this algorithm it is possible to reproduce an image with different gray levels by means of a device able to defineonly white and black points. The mask of the Floyd-Steinberg's algorithm was chosen in a way thata uniform distribution of gray intensities 1 2 produces a chessboard layout pattern.

By means of Processing, implement a program to process the file lena , a "dithered" black and white version of the famous Lena image. The image, treated only in the left half, should result similar to that of [link]

size(300, 420); PImage a; // Declare variable "a" of type PImagea = loadImage("lena.jpg"); // Load the images into the program image(a, 0, 0); // Displays the image from point (0,0)int[][] output = new int[width][height];for (int i=0; i<width; i++) for (int j=0; j<height; j++) { output[i][j] = (int)red(get(i, j));} int grayVal;float errore; float val = 1.0/16.0;float[][]kernel = { {0, 0, 0}, {0, -1, 7*val},{3*val, 5*val, val }}; for(int y=0; y<height; y++) { for(int x=0; x<width; x++) { grayVal = output[x][y];// (int)red(get(x, y));if (grayVal<128) errore=grayVal; else errore=grayVal-256;for(int k=-1; k<=1; k++) { for(int j=-1; j<=0 /*1*/; j++) { // Reflect x-j to not exceed array boundaryint xp = x-j; int yp = y-k;if (xp<0) { xp = xp + width;} else if (x-j>= width) { xp = xp - width;} // Reflect y-k to not exceed array boundaryif (yp<0) { yp = yp + height;} else if (yp>= height) { yp = yp - height;} output[xp][yp] = (int)(output[xp][yp] + errore * kernel[-j+1][-k+1]);} }} }for(int i=0; i<height; i++) for(int j=0; j<width; j++) if (output[j][i]<128) output[j][i]= 0; else output[j][i] = 255;// Display the result of dithering on half imageloadPixels(); for(int i=0; i<height; i++) { for(int j=0; j<width/2; j++) { pixels[i*width + j]= color(output[j][i], output[j][i], output[j][i]);} }updatePixels();

Got questions? Get instant answers now!

Questions & Answers

A golfer on a fairway is 70 m away from the green, which sits below the level of the fairway by 20 m. If the golfer hits the ball at an angle of 40° with an initial speed of 20 m/s, how close to the green does she come?
Aislinn Reply
cm
tijani
what is titration
John Reply
what is physics
Siyaka Reply
A mouse of mass 200 g falls 100 m down a vertical mine shaft and lands at the bottom with a speed of 8.0 m/s. During its fall, how much work is done on the mouse by air resistance
Jude Reply
Can you compute that for me. Ty
Jude
what is the dimension formula of energy?
David Reply
what is viscosity?
David
what is inorganic
emma Reply
what is chemistry
Youesf Reply
what is inorganic
emma
Chemistry is a branch of science that deals with the study of matter,it composition,it structure and the changes it undergoes
Adjei
please, I'm a physics student and I need help in physics
Adjanou
chemistry could also be understood like the sexual attraction/repulsion of the male and female elements. the reaction varies depending on the energy differences of each given gender. + masculine -female.
Pedro
A ball is thrown straight up.it passes a 2.0m high window 7.50 m off the ground on it path up and takes 1.30 s to go past the window.what was the ball initial velocity
Krampah Reply
2. A sled plus passenger with total mass 50 kg is pulled 20 m across the snow (0.20) at constant velocity by a force directed 25° above the horizontal. Calculate (a) the work of the applied force, (b) the work of friction, and (c) the total work.
Sahid Reply
you have been hired as an espert witness in a court case involving an automobile accident. the accident involved car A of mass 1500kg which crashed into stationary car B of mass 1100kg. the driver of car A applied his brakes 15 m before he skidded and crashed into car B. after the collision, car A s
Samuel Reply
can someone explain to me, an ignorant high school student, why the trend of the graph doesn't follow the fact that the higher frequency a sound wave is, the more power it is, hence, making me think the phons output would follow this general trend?
Joseph Reply
Nevermind i just realied that the graph is the phons output for a person with normal hearing and not just the phons output of the sound waves power, I should read the entire thing next time
Joseph
Follow up question, does anyone know where I can find a graph that accuretly depicts the actual relative "power" output of sound over its frequency instead of just humans hearing
Joseph
"Generation of electrical energy from sound energy | IEEE Conference Publication | IEEE Xplore" ***ieeexplore.ieee.org/document/7150687?reload=true
Ryan
what's motion
Maurice Reply
what are the types of wave
Maurice
answer
Magreth
progressive wave
Magreth
hello friend how are you
Muhammad Reply
fine, how about you?
Mohammed
hi
Mujahid
A string is 3.00 m long with a mass of 5.00 g. The string is held taut with a tension of 500.00 N applied to the string. A pulse is sent down the string. How long does it take the pulse to travel the 3.00 m of the string?
yasuo Reply
Who can show me the full solution in this problem?
Reofrir Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

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