Transcribed TextTranscribed Text

Assignment 4 “The medium is the message.” The emphasis for this assignment is processing the contents of a collection (through the pixels of a picture). In preparation for this assignment, create a folder called Assign_4 for submission of the assignment and two subfolders: Assign_4_A and Assign_4_B for the two DrJava projects for the assignment. Part A – A Poster When a poster is printed, it is sometimes printed with a reduced colour palette, for example instead of 256 levels for each colour component (i.e. 16 million colours), only a small number such as 4 (giving only 64 distinct colours) is used. The effect on the image is called “posterizing”. For example, the following picture: After being posterized would look like: Write a program that inputs a picture, displays it (waiting for the user) and then posterizes it to have only 4 levels per colour channel. Use the PictureDisplayer that sizes to the size of the picture. What we want to do is reduce each colour channel from the range 0-255 (8 bits) to the range 0-3 (2 bits). We can do this by dividing the colour channel value by 64. Using integer division, this will give us a value 0-3. However, since our actual display still uses 1 byte per colour channel, values 0-3 will all look very much like black (very low colour intensity). To make it look right, we need to scale the values back up to the original range (multiply by 64). This means that only 4 colour channel values will occur: 0, 64, 128 and 192, imitating a 2-bit colour palette. Part B – A Night's Sky: In lecture, we wrote a program to remove redeye from a photograph. In lab we wrote a program to do “Green Screening”. In each case we measured the colour distance between the colour of each pixel and RED (for redeye) or GREEN (for green screening), and then made a decision to change colour by comparing that distance to a predetermined tolerance. The same technique can be used to remove a background of a single colour, or to replace other areas of consistent colouring. In this assignment, you'll be replacing a blue sky with a night sky. As an added feature you will randomly add stars to the night sky. The methodology is straightforward. Examine each pixel of the picture and if it is within a reasonable distance of sky blue (Color(8431307)) change the colour of the pixel to a very dark blue (Color(1054800)). However, approximately once in every 2,000 sky pixels processed (i.e. with probability 0.0005), instead of using dark blue, use a white colour (Color(16777088)), producing a star in the sky. Hints:  Use the PictureDisplayer constructor that sizes to the size of the picture.  You will process all of the pixels.  You must check to see if the pixel colour is close to sky blue and change the colour if so. (You will have to experiment to find a tolerance that works. Something around 65 works for the supplied picture.)  When replacing the colour, you need to randomly (with probability 0.0005) use white rather than dark blue. (Generate a random double in [0,1) and, if it is less than 0.0005, use white.)  Make sure the user has time to see the original picture, as well as the processed picture, and save the final modified result in a new file. You may try it on your own photo that includes a skyline if you wish, but you will then need to determine the best 'blue' to use. Before: After

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import Media.*;                  // for Picture and PictureDisplayer
import java.awt.*;               // for Color objects and methods
import static java.lang.Math.*; // for math constants and functions
import static java.awt.Color.*; // for Color constants

* @author
public class Assign_4_A {

    public Assign_4_A() {

       Picture pic = new Picture();
       PictureDisplayer display = new PictureDisplayer();


       while (pic.hasNext()) {
            // get a pixel
            Pixel p =;
            // set its new color...

By purchasing this solution you'll be able to access the following files:

for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats