Comp 2673
Homework 2 Solutions
Two topics: Unix and fractal image compression

    Unix questions:

    1. List some consequences of working on a multi-user system (at least 3).
      • Processor is shared - you must be aware of your impact when running computationally-intensive programs.
      • Disk space is shared - be aware of your usage
      • You and others may be logged in remotely - never reboot the machine or disconnect the internet.
    2. Compare using a graphical user interface with using a command line interface by listing some pro-GUI/pro-command line pairs (at least 3).
      • GUI more intuitive than command line (easier for beginners), while command-line interface requires expertise to use.
      • GUI slower to use than command line, command-line interfaces are faster and more flexible.
      • On GUI systems, you never get faster, on command-line the more experience you have, the more efficient you are.
      • On command-line systems, you can combine commands to get great flexibility.
    3. Say you create a file on the Sun machines called .format. When you enter the command ls, your new file doesn't show up! What is going on? How do you see a listing of this file?
      The ls command suppresses display of files that start with a ".". To see all files, type ls -a
    4. Say you receive email from a Sun user complaining that you are running a process that is hogging the machine. Explain the exact process you would go through in response (include the exact commands you would type)
      Use top or ps to find the process id, then type renice num pid, where num is a number from 1-19 and pid is the process id.
    5. Say you log onto a machine, run top and see that you own the top process. You didn't even realize it was running and want to kill it. What do you do?
      Type jobs to find the job number and type kill %job_no. Alternately, remember the process id while you are running top and type kill pid.
    6. True or False: If the Sun lab is very cold and the AC is running full blast, you should turn it off to save power.
      False! The air conditioner should be running - the computers can fail if the temperature gets too high. If you really think there's a problem, please contact Ivan Fetch.
    7. True or False: If the door to the Sun lab is propped open, you should close it.
      True - access to the Sun lab is restricted to students in CS classes. Close the door to limit access.

    PIFS and fractal image compression/decompression questions:

    1. Say that our image is 512x1024 pixels, and the range rectangles are 16x16 pixels. How many range rectangles are there? How many domain rectangles must be compared for each range rectangle? Show your calculations and explain.
      There are 512/16 × 1024/16 = 32 × 64 = 2048 range rectangles. The domain rectangles are 32 by 32 pixels. For each range rectangle, we have 481 × 993 = 477,633 domain rectangles to check.
    2. Say we're doing fractal image compression/decompression using the method discussed in class. Say that the variables
      double s, o;
      are set to the appropriate values to represent contrast and brightness constants. Say that the variable
      unsigned char domainimage[8][8];
      contains the appropriate scaled-down portion of the original image. Write the 3-5 lines of code that use s and o to adjust the contrast and brightness of domainimage.
           int scaled_value, i, j;
           for (i=0; i < 8; i++) {
               for (j=0; j < 8; j++) {
                   scaled_value = domainimage[i][j]*s + o;
                   if (scaled_value < 0) scaled_value = 0;
                   if (scaled_value > 255) scaled_value = 255;
                   domainimage[i][j] = scaled_value;
               }
           }
      
    3. Our method of saving the PIFS information is very inefficient. Since we are saving the numbers as text, it takes several bytes to store a one-byte integer. If we write to a file in binary, we can save an unsigned char as one byte, an int as 4 bytes, and a double as 4 bytes. If we did this, then how many bytes would our compressed file be if our image had 20 by 16 range regions, and each of which was 8x8 pixels? Show your work, and explain.
      First, the header has 4 integers, which takes 16 bytes. Now we have information for a 20 × 16 = 320 range regions. For each range region, we have 2 ints and 2 doubles, for a total of 16 bytes per range region. The total is 16 + 320 × 16 = 5136 bytes. Note: if a double is stored in 8 bytes, then the total is 16 + 320 × 24 = 7696.