Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Bonus Question: Create a script m-file which displays an image variable where the border of the image grows with a new color determined by the
Bonus Question: Create a script m-file which displays an image variable where the border of the image grows with a new color determined by the user's keyboard presses. You should use the waitforbuttonpress command within a while-loop to keep waiting for user inputs. Use the get ( gcf, 'CurrentCharacter') expression to obtain the most recently pressed keyboard key. You can assume the user will always press a keyboard key (you do not need to check for mouse clicks). Pressing the ' R ' key will grow the image by 2 pixels in both x and y dimensions, where the new pixels around the perimeter are red. The previous image should be displayed inside. Pressing ' G ', or ' B ' should have the same affect, except it should add a green, or blue border, respectively. Pressing the ' Q ' key should terminate your while-loop. (30 Points) The program can be initially started with a 11 black pixel image. The code below works to add a red border to a 11 black image using a temporary variable tmp, and a size variable called N. Every time we wish to grow the image, the dimensions of the image should increase by 2 (since we are adding a 1-pixel border to the perimeter). clear; clc; \% Start with a fresh Workspace and CMD Window img = uint8 ( zeros (1,1,3));% Create a black 11 pixel image; each pixel has [R,G,B] figure(1); clf; \% Open a new figure (\#1) and clear the figure image (img); \% Display the 11 black image N=1;% We start with a 11 image initially \% If we determine that the user pressed the "R" key, do the following... N=N+2; \% We will grow our dimensions by 2 pixels tmp= uint8 (zeros(N,N,3));% Create temp image variable with correct new size tmp(:,:,1)=255; \%Set temp image variable to be all RED \%The above will need to change depending on key pressed tmp([2:N1],[2:N1],:)=img;% Place the previous image inside of the temp variable img = tmp; \% Store the newly grown temp image into the img variable image(img); \%Display the new image Hints: setup a while-loop to check the most recent button press against the ' q ' key. Within the loop, use if-statement \& switch statement to increment N by 2, grow the image variable, and displav the new image based on the kevs
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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