<< 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

what does preconceived mean
sammie Reply
physiological Psychology
Nwosu Reply
How can I develope my cognitive domain
Amanyire Reply
why is communication effective
Dakolo Reply
Communication is effective because it allows individuals to share ideas, thoughts, and information with others.
effective communication can lead to improved outcomes in various settings, including personal relationships, business environments, and educational settings. By communicating effectively, individuals can negotiate effectively, solve problems collaboratively, and work towards common goals.
it starts up serve and return practice/assessments.it helps find voice talking therapy also assessments through relaxed conversation.
miss
Every time someone flushes a toilet in the apartment building, the person begins to jumb back automatically after hearing the flush, before the water temperature changes. Identify the types of learning, if it is classical conditioning identify the NS, UCS, CS and CR. If it is operant conditioning, identify the type of consequence positive reinforcement, negative reinforcement or punishment
Wekolamo Reply
please i need answer
Wekolamo
because it helps many people around the world to understand how to interact with other people and understand them well, for example at work (job).
Manix Reply
Agreed 👍 There are many parts of our brains and behaviors, we really need to get to know. Blessings for everyone and happy Sunday!
ARC
A child is a member of community not society elucidate ?
JESSY Reply
Isn't practices worldwide, be it psychology, be it science. isn't much just a false belief of control over something the mind cannot truly comprehend?
Simon Reply
compare and contrast skinner's perspective on personality development on freud
namakula Reply
Skinner skipped the whole unconscious phenomenon and rather emphasized on classical conditioning
war
explain how nature and nurture affect the development and later the productivity of an individual.
Amesalu Reply
nature is an hereditary factor while nurture is an environmental factor which constitute an individual personality. so if an individual's parent has a deviant behavior and was also brought up in an deviant environment, observation of the behavior and the inborn trait we make the individual deviant.
Samuel
I am taking this course because I am hoping that I could somehow learn more about my chosen field of interest and due to the fact that being a PsyD really ignites my passion as an individual the more I hope to learn about developing and literally explore the complexity of my critical thinking skills
Zyryn Reply
good👍
Jonathan
and having a good philosophy of the world is like a sandwich and a peanut butter 👍
Jonathan
generally amnesi how long yrs memory loss
Kelu Reply
interpersonal relationships
Abdulfatai Reply
What would be the best educational aid(s) for gifted kids/savants?
Heidi Reply
treat them normal, if they want help then give them. that will make everyone happy
Saurabh
What are the treatment for autism?
Magret Reply
hello. autism is a umbrella term. autistic kids have different disorder overlapping. for example. a kid may show symptoms of ADHD and also learning disabilities. before treatment please make sure the kid doesn't have physical disabilities like hearing..vision..speech problem. sometimes these
Jharna
continue.. sometimes due to these physical problems..the diagnosis may be misdiagnosed. treatment for autism. well it depends on the severity. since autistic kids have problems in communicating and adopting to the environment.. it's best to expose the child in situations where the child
Jharna
child interact with other kids under doc supervision. play therapy. speech therapy. Engaging in different activities that activate most parts of the brain.. like drawing..painting. matching color board game. string and beads game. the more you interact with the child the more effective
Jharna
results you'll get.. please consult a therapist to know what suits best on your child. and last as a parent. I know sometimes it's overwhelming to guide a special kid. but trust the process and be strong and patient as a parent.
Jharna
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