QuestionQuestion

Transcribed TextTranscribed Text

Note that you do not have to generate the tree only the resultant image. Assignment Instructions: Enclosed is a PGM (or PGMA for PGM ASCII) image – baboon.pgma as well as the Wikipedia description of the format. You can use GIMP or ImageMagick to display pgma images. Additionally you can use Photoshop / Linux. Your tasks are: 1. Develop a program to create a quad tree based image of an input pgma image with up to 256-gray levels. The program should have a parameter β€œvariance threshold” that can get values between 0 and 1024. a. First, the program treats the entire image as a quad b. Next, for each quad i. If the quad contains only one pixel the program stops ii. If the variance of the quad is equal to or below the threshold, the program replaces the entire pixels of the quad with the average value of the pixels in the quad and stops. Note: You should actually create a new pgma image and when you write the new value of a quad you should write it into the new pgma image. iii. If the variance of the quad is above the threshold the program divides the quad into four even quads and works on each of these quad recursively. Note: the definition is recursive. Yet, recursive implementation is very inefficient and can result in a very slow execution or stack overflow. Nevertheless, it is easier to develop the recursive version of the program. So, you are allowed to use recursion 2. Test your program with the original baboon image using variance the thresholds 0, 16, 64, and 256. 3. You can use other images from TRACS for further testing. 4. Run an LZ based compression program such as zip, pkzip, rar, and UNIX compress on the original image and on the quad based generated image and report the sizes before and after compression. Analyze the result of these values. Notes: 1) You do not have to write the LZ based program. Use any available program. 2) To estimate 𝑝̅the average of pixels in a quadrant use: 𝑝̅= 1 𝑁 βˆ‘ 𝑃𝑖 𝑁 𝑖=1 where 𝑃𝑖 is a pixel in the quadrant. 3) To estimate the quadrant variance (𝜎 2 ) use 𝜎 2 = 1 π‘βˆ’1 βˆ‘ (𝑃𝑖 𝑁 𝑖=1 βˆ’π‘ƒπ‘– Μ…) 2 PGMA Files Portable Gray Map (ASCII) PGMA is the ASCII portable gray map format. It is a simple grayscale image description. The definition is as follows: ο‚· The typical file extension is ".pgm", but an extension of ".pnm" is also occasionally used. ο‚· A "magic number" for identifying the file type. An ASCII PGM file's magic number is the two characters "P2". ο‚· Whitespace (blanks, TABs, CRs, LFs). ο‚· A width, formatted as ASCII characters in decimal. ο‚· Whitespace. ο‚· A height, again in ASCII decimal. ο‚· Whitespace. ο‚· The maximum gray value, again in ASCII decimal. ο‚· Whitespace. ο‚· Width * height gray values, each in ASCII decimal, between 0 and the specified maximum value, separated by whitespace, starting at the top-left corner of the gray map, proceeding in normal English reading order. A value of 0 denotes black and the maximum value denotes white. ο‚· Characters from the β€œ#" to the next end-of-line are ignored (comments). No line should be longer than 70 characters. PGMA example The PGM and PPM formats (both ASCII and binary versions) have an additional parameter for the maximum value in a line between the X and Y dimensions and the actual pixel data. P2 # Shows the word "FEEP" (example from Netpbm man page on PGM) 24 7 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0 0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0 0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0 0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0 0 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Example:

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.

// Method to threshold PGMAQuadTree object
public void threshold(int threshold) {
    matrix = threshold(matrix, threshold);
}

// Recursive helper method to threshold int array
private int[][] threshold(int[][] array, int threshold) {
    int w = array[0].length;
    int h = array.length;
   
    if (w == 1 || h == 1) {
      return array;
    }
    if (variance(array) < threshold) {
      for (int i = 0; i < h; i++) {
       for (int j = 0; j < w; j++) {
          array[i][j] = mean(array);
       }
      }
      return array;
    }
    // TOP LEFT QUAD
    int[][] quad = new int[h/2][w/2];
    for (int i = 0; i < h/2; i++) {
      for (int j = 0; j < w/2; j++) {
       quad[i][j] = array[i][j];
      }
    }
    quad = threshold(quad, threshold);
    for (int i = 0; i < h/2; i++) {
      for (int j = 0; j < w/2; j++) {
       array[i][j] = quad[i][j];
      }
    }
    // BOTTOM LEFT QUAD
    quad = new int[h-h/2][w/2];
    for (int i = h/2; i < h; i++) {
      for (int j = 0; j < w/2; j++) {
       quad[i - h/2][j] = array[i][j];
      }...

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

$59.00
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.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
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