Recitation 2: Image Files
In this recitation, you will explore how image files are stored.
Preparation
Prepare by watching: “How Computers Work: Binary & Data”
Activity
This activity should be completed individually, though you are welcome to ask other students, the TAs, or the instructor for help.
Task 1: View the File Sizes of Two Photos
- Use your phone to take two photos:
- For one photo, cover the lens of your camera with your finger
- The other photo can be of anything else in the room
- Copy these photos from your phone to your computer
- Record the file sizes of each photo:
- On macOS: Right-click on a photo, then choose “Get Info”
- On Windows: Right-click on a photo, then choose “Properties”
- Using the table shown below, convert the file sizes (likely displayed as MB, or megabytes) to bytes
- Discuss with a neighbor:
- Which photo is the largest (i.e., has the most bytes)?
- Why do you think that photo is the largest?
Metric | Size |
---|---|
byte | \(8\) bits |
kilobyte (KB) | \(1000\) bytes |
megabyte (MB) | \(1000^2\) bytes |
gigabyte (GB) | \(1000^3\) bytes |
terabyte (TB) | \(1000^4\) bytes |
Task 2: Resize a Photo
Next, you will resize a photo so it takes up less space on your computer.
- Install GIMP, a free graphics editor
- Open the larger of your two photos in GIMP
- Choose “Image”, “Scale Image…”
- A window will open, showing the dimensions of the image, in pixels.
- Edit the width (e.g., to 500 pixels)
- Click on the height, and you will see that it is updated automatically. This is done to preserve the aspect ratio, or else the image will appear stretched.
- Finally, click “Scale”
- Choose “File”, “Export As…”
- Name your file to distinguish it from the original photo (e.g., name it “resized”)
- Click “Select File Type (By Extension)”, then choose “JPEG image”
- Click “Export”, then “Export” in the window that appears
- Compare the file sizes of the resized photo to the original. Which is larger?
- Compare the file types of the two photos. Are they the same, or different? Many different image file formats exist. Each image format stores images differently, which impacts file size. Common formats are:
- PNG: Portable Network Graphics
- JPEG: Joint Photographic Experts Group
- HEIF: High Efficiency Image File Format
- TIFF: Tagged Image File Format
Task 3: Experiment (Optional)
- Visually compare the quality of your original image to the resized version. Can you see a difference? If not, try zooming in.
- There is an inherent tradeoff between image quality and file size: the larger an image file, the more details it can store.
- Try to find an optimal tradeoff between image quality and file size for your photo by resizing the original photo to different sizes.
- Instead of exporting your resized photo as a JPEG, try a different image file format (e.g., a PNG). Which file is larger?
- Create a blank image by choosing “File”, “New…”
- Draw on the image using the paintbrush tool. For example, you might sign your name. Export the image as a JPEG, and inspect its file size.
- Add more details to your image, re-export the image, and see how the file size changes.
Submit
Upload a PDF to Moodle containing:
- Your name
- The date and time of the recitation session you attended
- If you could not attend a recitation session, simply explain why you could not attend
- The two photos you took, and the file sizes of each photo
- For the larger photo: the file type and file size, before and after resizing
- Any results from the optional experiment