Prompts the user for the name of hisher jpg file using an


Write a script file that does the following:

  • Prompts the user for the name of his/her jpg file using an input statement.  Set up your input statement to expect a string.
  • Uses the imread command to read in the jpg image.  Note: the filename will already be a string so don't use single quotes around it again.
  • Converts the color image to a grayscale image called Pic.
  • Prompts the user for a Threshold value from 0 to 255.
  • If the user enters an invalid value for Threshold, the script continues to prompt the user for a valid value until the user finally manages to follow directions.
  • Determine the size of Pic.
  • Create a new matrix called NewPic which is the same size as Pic, contains all zeros, and is type uint8.  Note: everything in MATLAB defaults to a double.  Use the uint8 function to convert to this variable type.  Ex.  M = uint8(M) will convert an array M to type uint8.
  • Use the conversion formula given above and the value of Threshold entered by the user to make NewPic a pure black and white image.
  • Use the imshow command to display the original grayscale image.  Add a title indicating that this is the original image.
  • Use the command figure to open a new figure window then use the imshow command to display the black and white image.  Add a title indicating that this is the Black and White image.

Solution Preview :

Prepared by a verified Expert
Mechanical Engineering: Prompts the user for the name of hisher jpg file using an
Reference No:- TGS01377238

Now Priced at $30 (50% Discount)

Recommended (96%)

Rated (4.8/5)