Problem Analysis and Modular Design
Before creating an operation in Stage2, it is essential to analyze the workflow and determine how best to represent it as a set of modular tasks. While some workflows benefit from breaking down each step into distinct operations, others, like the one described below, are more suited to grouping related tasks into a single operation for simplicity and clarity.
Workflow Overview
Objective:
Prepare raw images for training a machine learning model, such as object detection or classification. The preprocessing ensures consistent input quality and format.
Steps in the Workflow:
- Input raw images.
- Convert images to grayscale.
- Crop each image to a region of interest (ROI).
- Enhance the contrast of the images.
- Normalize pixel values.
- Save the processed images into a dataset.
Modular Design: Single Operation for Preprocessing
While each of these steps could be implemented as distinct operations, they all fall under the same high-level task: preprocessing an image. To maintain simplicity and better reflect the intent of the workflow, we will group all these steps into a single operation called Preprocess Image.
Operation: Preprocess Image
Description:
The Preprocess Image operation takes in a raw image and performs a series of preprocessing tasks to standardize it for machine learning workflows.
Tasks Performed:
- Convert to Grayscale: Simplifies image data and reduces complexity.
- Crop to Region of Interest (ROI): Focuses on the relevant portions of the image.
- Increase Contrast: Enhances visual distinctions.
- Normalize Pixel Values: Scales pixel intensities to a consistent range (e.g.,
[0, 1]
). - Save the Processed Image: Outputs the final preprocessed image for further use.
Parameters:
- inputPath: The path to the raw image file.
- outputPath: The path to save the processed image.
- roi (optional): Coordinates for cropping the image (e.g.,
[x1, y1, x2, y2]
). - contrastFactor (optional): A multiplier to adjust the contrast level.
- normalizationRange (optional): The range to normalize pixel values, e.g.,
[0, 1]
or[-1, 1]
.
Output:
A fully preprocessed image ready for training machine learning models.
Why Group Tasks into a Single Operation?
- Single Responsibility: The Preprocess Image operation encapsulates a logically unified task, making it easier to understand and use.
- Efficiency: Reducing the number of operations simplifies workflow construction and execution.
- Reusability: The operation can be reused in any workflow requiring image preprocessing, without needing to manage multiple distinct operations.
- Scalability: If needed, the operation can be expanded or split in the future as workflows become more complex.
Note that since we are using parameters to control the process, if we wanted to preprocess an image but wanted to do so without any one of the steps (say, we wanted to retain the orignal contrast level) we could simply set the parameter: contrastFactor to 1, which will leave the contrast at default level
In General The more atomic you make your operation, the more re-usable its going to be, granting more flexibility. Monolithic operations are more complex to create and more specialized to use. When in doubt, break it up. For example, if we decide down the line that we only want to use this operation to crop an image to ROI, we have all this unecessary functionality that we need to remember to set to defaults.
Next Steps
Now that we’ve analyzed the problem and decided to encapsulate the workflow as a single operation, the next step is to choose a tool to implement the preprocessing functionality.
Continue to the next section: Selecting Tools for Operations.