Customizing red_filter#

Previously, you learnt how to define a function to apply the red filter to an entire image as follows:

Modifying the above code for Applying red filter to a specified region in an image#

Now, let us modify the above function so that the red filter is applied to only the specified region. We will call the new function custom_red_filter. We need to make the following changes to the above function so that it can be customized to a specific region:

  • We need the function to take in three more parameters as inputs: top_left, height and width

  • We need to modify the range inputs of the outer for loop to go over only the specified region. The range function’s starting point from where we need to iterate would be the row index specified by the top_left tuple which is given by top_left[0] . The iteration should stop once we reach the specified height so the range function’s ending point would be top_left[0] + height.

  • We need to modify the range inputs of the inner for loop to go over only the specified region. The range function’s starting point from where we need to iterate would be the column index specified by the top_left tuple which is given by top_left[1] . The iteration should stop once we reach the specified width so the range function’s ending point would be top_left[1] + width.