Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Task 7 : Changing brightness / contrast of an image: 2 0 points We can write a function that can change the brightness of an
Task : Changing brightnesscontrast of an image: points
We can write a function that can change the brightness of an rgb image. There are a lot of Python libraries that can do that. We will try to create a function that accepts an RGB image and a scale factor. In simple words you can think of changing brightness of an image as increasing or decreasing the pixel intensities by a factor.
We will create this function and it should only accept scale factor values between any value greater than causes an overflow exception which is beyond the scope of this project. But we will try and catch this exception.
Here are the detailed steps to creating and calling this function with exception handling, please follow the steps carefully:
The code for reading the image is given to you.
Create a function and name it rgbbrightness. This function accepts parameters: rgbimage and factor.
Inside this function: if factor or factor just return don't do anything else. The if clause ends right here
Get the width, height and number of planes it will be for RGB image from rgbimage.shape
Loop through the width and the height values for loops, one within the other Use x and y as the looping variables: eg: for x in rangewidth:
Inside the inner loop after for y in rangeheight: get the red, blue and green values for the current width and position in the variables rg and b
Create new variables: augr augg augb which are equal to the r g and b values multiplied by factor. Also make sure that the final values are integers. use int
Create another variable: augmentedimage. Now you will write code statements that each assign the augr augg and augb values to the current pixels AND plane to augmentedimage.
return augmentedimage
Now we want to call this function but let's include exception handling to make sure that when factor is greater than or less than the exception is catched without throwing an error:
The try and except blocks are aredy given to you. The code inside the try block is the same as other function calling blocks that were given to you.
Inside the try block, call the rgbbrightness function with imgarr and factor value of Return the image in the variable: augmented
Convert augmented to a numpy array
Make sure augmnted is of type int
The next two lines of code are already given to you
Inside the except block: print: 'The factor value you entered is invalid. Please enter a value between and
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started