Question: Given: Select.java import java.util.Random; public class Select { static Random rm; public static void main(String[] args) { rm = new Random(); int[] A = {

Given:
Select.java
import java.util.Random;
public class Select {
static Random rm;
public static void main(String[] args) { rm = new Random(); int[] A = { 7, 2, 6, 6, 4, 3, 5, 0, 11, 6 };
for (int j = 0; j
static int select(int[] A, int i, int j, int q) { // select qth smallest if (i == j) return A[i]; int pivotindex = i + rm.nextInt(j - i + 1); // Pick a random pivot swap(A, pivotindex, j); // Stick pivot at end
// k will be the first position in the right subarray int k = partition(A, i - 1, j, A[j]); swap(A, k, j); // Put pivot in place
int sz = k - i; if (q == sz + 1) return A[k]; else if (q
static int partition(int[] A, int l, int r, int pivot) { do { // Move bounds inward until they meet while (A[++l] = pivot)) ; swap(A, l, r); // Swap out-of-place values } while (l
private static void swap(int[] A, int i, int j) { int temp = A[j]; A[j] = A[i]; A[i] = temp; } }
------------------
Blur.java
import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.util.Scanner; import java.util.ArrayList; import java.io.*; import java.util.Arrays;
public class Blur {
public static void main(String[] args) throws IOException { int pics = 17; File[] file = new File[pics]; //String prefix = "/afs/cad.njit.edu/courses/ccs/s15/cs/114/common/Birds/"; String prefix = ""; for (int p = 1; p
long start = System.currentTimeMillis();
// create a scanner for each of the pictures // Scanner[] scan = new Scanner[pics];
int rows = 0, cols = 0, mx = 0; for (int i = 0; i
// open output file and print out header
BufferedWriter output = new BufferedWriter(new FileWriter("blurred.ppm")); output.write(String.format("%s ", "P3")); output.write(String.format("%d %d ", cols, rows)); output.write(String.format("%d ", mx)); System.out.println(rows + ", " + cols + ", " + mx);
for (int i = 0; i
for (int i = 0; i
e purpose of this assignment is to explore an application of selection. The goal is to "un-clutter" a set of images. The Birds directory on moodle contains a set of seventeen files, birds1.ppm through birds17.ppm, storing images in the PPM (Portable Pixel Map) format. The background is similar for each image, but each has some clutter (attacking birds). The directory also contains Blur.java, which has the boilerplate code to open and read in the files, and also write an output file (it just averages the pixel values over the images). You need to write a program Th (call it Clear.java) that produces an image file with the clutter removed. The images are sampled from a scene in the Alfred Hitchcock move "The Birds"; you can see the clip at https://www.youtube.com/watch?v-hplpQt424Ls. Promise that you won't use the image files for commercial entertainment purposes. The PPM files are plain text files with the following format. The first line gives the image type, which is always "P3" for this exercise. The next line has two integers giving the number of columns and rows of the image. The next line has an integer giving the maximum level for any color. Then the rest of the file is a sequence of integers, three for each pixel, giving the red, green, and blue intensities For example, consider the following image file: P3 3 4 255 255 0 0 0 255 00 0 255 000 255 255 255 120 120 120 255 255 0 255 0 255 0 255 255 100 100 100 200 200 200 0 100 0 The first three lines are the header, with the first line indicating that this is a P3 (plain) image. The next line tells us that this image has 3 columns and 4 rows of pixels. The next line gives the maximum intensity level of 255; all subsequent numbers in the file are between 0 and the maximum 255. The following lines give the red, green, blue values for each pixel; the first pixel has intensities 255 (red), 0 (green) and 0 (blue), so the top left pixel is red. The next pixel is green and the last pixel on the first row is blue. The first pixel on the second row is black (all three intensities equal to zero) On the Linux machines in the OSL lab, you can display a ppm image by clicking on it. On a Windows machine, you can display PPM images using, for example, the LibreOffice Draw program or the ppmReader.html file in the Birds directory (open it with the Chrome browser) Be prepared to demonstrate your program during our next class. Your program should produce an image that shows what the view from the car would be if there were no birds e purpose of this assignment is to explore an application of selection. The goal is to "un-clutter" a set of images. The Birds directory on moodle contains a set of seventeen files, birds1.ppm through birds17.ppm, storing images in the PPM (Portable Pixel Map) format. The background is similar for each image, but each has some clutter (attacking birds). The directory also contains Blur.java, which has the boilerplate code to open and read in the files, and also write an output file (it just averages the pixel values over the images). You need to write a program Th (call it Clear.java) that produces an image file with the clutter removed. The images are sampled from a scene in the Alfred Hitchcock move "The Birds"; you can see the clip at https://www.youtube.com/watch?v-hplpQt424Ls. Promise that you won't use the image files for commercial entertainment purposes. The PPM files are plain text files with the following format. The first line gives the image type, which is always "P3" for this exercise. The next line has two integers giving the number of columns and rows of the image. The next line has an integer giving the maximum level for any color. Then the rest of the file is a sequence of integers, three for each pixel, giving the red, green, and blue intensities For example, consider the following image file: P3 3 4 255 255 0 0 0 255 00 0 255 000 255 255 255 120 120 120 255 255 0 255 0 255 0 255 255 100 100 100 200 200 200 0 100 0 The first three lines are the header, with the first line indicating that this is a P3 (plain) image. The next line tells us that this image has 3 columns and 4 rows of pixels. The next line gives the maximum intensity level of 255; all subsequent numbers in the file are between 0 and the maximum 255. The following lines give the red, green, blue values for each pixel; the first pixel has intensities 255 (red), 0 (green) and 0 (blue), so the top left pixel is red. The next pixel is green and the last pixel on the first row is blue. The first pixel on the second row is black (all three intensities equal to zero) On the Linux machines in the OSL lab, you can display a ppm image by clicking on it. On a Windows machine, you can display PPM images using, for example, the LibreOffice Draw program or the ppmReader.html file in the Birds directory (open it with the Chrome browser) Be prepared to demonstrate your program during our next class. Your program should produce an image that shows what the view from the car would be if there were no birds
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
