Lab 4 - Computational Thinking

Introduction

In this lab we're going to give you a little practice with computational thinking and stepwise refinement. We'll present the specifications for a small project (which is actually your Project 1) and walk you through a series of questions to think about how you might break down the project into smaller parts. When you are done, you'll have at least a partial possible design for building this project.

You can compare what you came up with to what we are going to actually have you do in Project 1. One of the great things about computer programming is there really isn't a "wrong" answer. So don't feel bad if you came up with a different design than what we present in Project 1. Your design might even be better. The only "wrong" answer is one that doesn't do the required task. One design might have advantages or disadvantages compared to other designs such as being more or less effiecient, easier to maintain, easier to understand, etc. but the most important first step is that it works. We'll talk about some of those other concepts as the semester progresses.

There will be nothing submitted to Gradescope for this lab. Instead, you'll submit your answers to the questions in the lab on Canvas. You could either open a text document and record your answers there and then copy them over to Canvas, or open the Lab04 assignment in Canvas and enter the answers directly.

Project Specification

Background

In this day and age, it seems like almost everyone is carrying a camera in their pocket. But the pictures aren't always what we want them to be and sometimes need a little bit of a touch up or need to be manipulated in some way.

This project will build a small python application that will accept input from the user in the form of command-line arguments and then manipulate the provided images based on the input given.

Requirements

Our little program should have the following qualities.

Input

  • All user input will be in the form of command-line arguments
  • All command-line arguments should be validated before any processing occurs.
    • If valid, the operation should occur
    • If invalid, an error message should be printed for the user
  • Commands will be of the following form: <operation flag> [<argument 1> <argument 2> ...]
    • <operation flag> determines what the processing operation should be. The operation flag will be of the form - where is a single letter, e.g. '-g', '-d', etc.
    • each operation flag has 0 or more arguments determined by the operation
    • most operations will have at least an input filename as an argument

Output

Most operations will result in the creation of a new output image. The output image name will be provided by the user as one of the input parameters.

Operations

The program should support the following operations:

  • Display an image using the system's default image viewer
  • Apply a grayscale filter
  • Apply a sepia filter
  • Apply a darkening filter - The user will supply the darkening factor
  • Add borders to an image - The user will supply the border width and RGB color values for the border
  • Flip an image vertically
  • Mirror an image horizontally
  • Build a collage of four equally sized images with black borders - The user will supply a border width to use around and between the images. For example if a 50 pixel border width is given, there will be 50 pixels of black on the top, bottom, left, and right of the collage, with a 50 pixel border between each image vertically and horizontally. Images will be arranged according to the following diagram:
  • Do a simple green screen composite image - The user will supply threshold and factor parameters for the compositing

Part 1 - Initial Breakdown

For all of the questions in this assignment, you would work toghether in a small group to discuss your ideas and thoughts and come up with a shared idea of what the breakdown should look like. You'll find that different people have different ideas and that as you discuss, they might provide insights you hadn't thought about. Be sure to give everyone a chance to share their ideas and don't let any one person dominate the discussion.

Task 1 - Identify Major Components

Given the requirements above, what do you see as the main, high level components or steps that the program needs to execute to function properly. Try to come up with at least three. These don't need a lot of detail in their descriptions, simple bullet points suffice.

Q1: List the major tasks you identified, one per line or as a bulleted list. List them in the order the program would complete them.

Task 2 - Breaking down the major components

The components you came up with in Task 1 are probably (and rightfully so) very high level concepts. The next step is to break them down into smaller tasks. Some tasks might just have one or two smaller sub-tasks. Others might haved several. It depends on the complexity of the major task. That's the goal of this part of the process: find the smaller tasks necessary to make it happen.

Again, we're not looking for deep descriptions, simple explanations of the idea are sufficent.

Q2: For each of the major components you identified, list the smaller sub-steps you identified that would be needed to accomplish or complete the larger task.

Task 3 - Continuing On

To completely finish a design, we'd then look at each of our sub-tasks and break them down further if necessary. And then examine any of those new tasks to see if they would need to be broken down.

That would continue until we've reached a sufficient granularity that and more breaking down of the tasks is easily done by writing code. That is usually a good place to stop. For some parts of our code, that may be only one or two levels deep and for others it could extend three, four, or more levels.

For this lab, we're not going to ask you to break it down any further but just identify any tasks that you think might need more thought.

Q3: Are there any of the sub-tasks you generated that are still somewhat complex and would benefit from further analysis? Which ones are they?

Part 2 - User Input

Our requirements specify that the user will be providing input to the program for each of the various processing tasks. It also says we need to validate that input. Let's identify what input values are needed for each processing task and look a little at how we might validate them.

Task 1 - Identify the processing tasks

The requirements identify a number of ways we need to be able to process an input image and say we need to have a operation flag of the form - where is a unique single letter identifier for the task.

Review the requirements and identify each processing task. For each one, determine the following:

  • a unique name for the task that might be useful as a function name to call to complete the task.
  • the information needed from the user to complete the task, i.e. input and output filenames, parameters, etc. These are the values we'll need to get as command-line arguments to the program.
  • a unique operation flag for each processing task.

Q4: List each operation name, its data values, and the operation flag you decided on.

Q5: Describe the process you used to create the operation flags. Did you have any issues or conflicts when determining them? How did you choose to resolve those conflicts?

Task 2 - Validating the input

One of the requirements is that we validate the user input and provide a message to the user if anything is wrong.

Q6: Look at the list of needed data for each operation. Are there similarities? Differences? How might that affect the way you get and validate the user input?

Q7: Again looking at the data that the user might input when running the program, what types of validation steps might you take to ensure that the input is good? Try to think of at least two or three concrete items that you could check to verify that the input is valid.

Q8: What type of error messages might you return if the checks you listed above fail? What information could/would you provide to the user. Provide specific messages that you might return.

Part 3 - Missing Information

You now have at least a partial design of a small image processing program. There are probably bits that could use some more detail, but we don't have time to flesh everything out in the lab (it's only supposed to take an hour). But there is one final question we need to think about when we're building a project.

Task 1 - What do I need to learn?

When we take on a new project, we almost inevitably encounter something that we don't know how to do. Sometimes that why we engage with a project, to learn new skills. These could be related to programming syntax, programming styles, the processes that the program needs to implement, or other topics. But it's important to identify where we are missing information so we can acquire the necessary knowledge.

Given the specification above, could you implement everything asked without learning any new material?

Q9: What parts of the project are you going to need to learn more about in order to implement the program? (And don't feel bad if this list is long. We expect it to be at this point.)

Conclusion

You now have a partial design for an image processing program. There are probably parts that need to be fleshed out a bit more and there are probably things you would need to learn in order to fully implement it.

The requirements we gave you are the specifications for Project 1. Go ahead and open the Project 1 instructions and look through them to answer the final question of the lab.

Q10 - Describe one thing you saw in the Project 1 instructions that is different from what you came up with and how it is different?

Submit your work

There is nothing to submit to Gradescope for this assignment. You should put the answers to all of the questions into the assignment on Canvas and submit there. There are no wrong answers to this assignment. As long as you put in a good faith effort and provide answers to the questions, you get full credit.

© 2024 Brigham Young University, All Rights Reserved