\[ \begin{align}\begin{aligned}\newcommand\blank{~\underline{\hspace{1.2cm}}~}\\% Bold symbols (vectors) \newcommand\bs[1]{\mathbf{#1}}\\% Poor man's siunitx \newcommand\unit[1]{\mathrm{#1}} \newcommand\num[1]{#1} \newcommand\qty[2]{#1~\unit{#2}}\\\newcommand\per{/} \newcommand\squared{{}^2} \newcommand\cubed{{}^3} % % Scale \newcommand\milli{\unit{m}} \newcommand\centi{\unit{c}} \newcommand\kilo{\unit{k}} \newcommand\mega{\unit{M}} % % Percent \newcommand\percent{\unit{\%}} % % Angle \newcommand\radian{\unit{rad}} \newcommand\degree{\unit{{}^\circ}} % % Time \newcommand\second{\unit{s}} \newcommand\s{\second} \newcommand\minute{\unit{min}} \newcommand\hour{\unit{h}} % % Distance \newcommand\meter{\unit{m}} \newcommand\m{\meter} \newcommand\inch{\unit{in}} \newcommand\foot{\unit{ft}} % % Force \newcommand\newton{\unit{N}} \newcommand\kip{\unit{kip}} % kilopound in "freedom" units - edit made by Sri % % Mass \newcommand\gram{\unit{g}} \newcommand\g{\gram} \newcommand\kilogram{\unit{kg}} \newcommand\kg{\kilogram} \newcommand\grain{\unit{grain}} \newcommand\ounce{\unit{oz}} % % Temperature \newcommand\kelvin{\unit{K}} \newcommand\K{\kelvin} \newcommand\celsius{\unit{{}^\circ C}} \newcommand\C{\celsius} \newcommand\fahrenheit{\unit{{}^\circ F}} \newcommand\F{\fahrenheit} % % Area \newcommand\sqft{\unit{sq\,\foot}} % square foot % % Volume \newcommand\liter{\unit{L}} \newcommand\gallon{\unit{gal}} % % Frequency \newcommand\hertz{\unit{Hz}} \newcommand\rpm{\unit{rpm}} % % Voltage \newcommand\volt{\unit{V}} \newcommand\V{\volt} \newcommand\millivolt{\milli\volt} \newcommand\mV{\milli\volt} \newcommand\kilovolt{\kilo\volt} \newcommand\kV{\kilo\volt} % % Current \newcommand\ampere{\unit{A}} \newcommand\A{\ampere} \newcommand\milliampereA{\milli\ampere} \newcommand\mA{\milli\ampere} \newcommand\kiloampereA{\kilo\ampere} \newcommand\kA{\kilo\ampere} % % Resistance \newcommand\ohm{\Omega} \newcommand\milliohm{\milli\ohm} \newcommand\kiloohm{\kilo\ohm} % correct SI spelling \newcommand\kilohm{\kilo\ohm} % "American" spelling used in siunitx \newcommand\megaohm{\mega\ohm} % correct SI spelling \newcommand\megohm{\mega\ohm} % "American" spelling used in siunitx % % Inductance \newcommand\henry{\unit{H}} \newcommand\H{\henry} \newcommand\millihenry{\milli\henry} \newcommand\mH{\milli\henry} % % Power \newcommand\watt{\unit{W}} \newcommand\W{\watt} \newcommand\milliwatt{\milli\watt} \newcommand\mW{\milli\watt} \newcommand\kilowatt{\kilo\watt} \newcommand\kW{\kilo\watt} % % Energy \newcommand\joule{\unit{J}} \newcommand\J{\joule} % % Composite units % % Torque \newcommand\ozin{\unit{\ounce}\,\unit{in}} \newcommand\newtonmeter{\unit{\newton\,\meter}} % % Pressure \newcommand\psf{\unit{psf}} % pounds per square foot \newcommand\pcf{\unit{pcf}} % pounds per cubic foot \newcommand\pascal{\unit{Pa}} \newcommand\Pa{\pascal} \newcommand\ksi{\unit{ksi}} % kilopound per square inch \newcommand\bar{\unit{bar}} \end{aligned}\end{align} \]

Oct 24, 2024 | 335 words | 3 min read

15.3.1. Task 1#

Learning Objectives#

Read and display images in MATLAB; Utilize image processing to modify data

Task Instructions#

  1. Draft a flowchart for this task and save it as ma4_ind_1_flowchart_username.pdf.

  2. Open the ENGR133_MATLAB_UDF_Template.m MATLAB template and complete the header information. Save your script as ma4_ind_1_username.m.

  3. Create a MATLAB program that reads block.png image file and outputs the image to the screen as Figure 1 using the imshow command. Properly label this image as “Color Original Image”.

  4. imread returns an array of row X column X frames. The number of frames for a colored image is generally ‘3’ (RGB) or ‘5’. Convert the image into a grayscale image using the built-in MATLAB function rgb2gray. Output the image to the screen as Figure 2 and label it as “Grayscale Original Image”

  5. Use the menu function in MATLAB to ask the user to choose either the colored original image or grayscale image.

Example user options:

Choose colored image

Choose grayscale image
  1. Use the menu function again to ask the user to select a flipping direction for the image they have chosen above.

Example user options:

Vertical Flip

Horizontal Flip

Diagonal Flip
  1. Open the ENGR133_MATLAB_UDF_Template.m MATLAB template and write the following user-defined functions:

    a. ma4_ind_1_vertical_username.m, which flips the image vertically (i.e. over a horizontal line that runs through the center of the image). Use only nested for loops to rotate the image.

    b. ma4_ind_1_horizontal_username.m, which flips the image horizontally (i.e. over a vertical line that runs through the center of the image). Use only nested for loops to rotate the image.

    c. ma4_ind_1_diagonal_username.m, flips the image over a diagonal line that runs from the top left to the bottom right of the image. Use either nested loops or transpose/permute to rotate the image. Permute can be used to rearrange the dimensions of a multidimensional array.

Example of using permute function:

A = [1 2; 3 4]; permute(A,[2 1])
ans =
     1     3
     2     4
X = rand(5,2,1);
Y = permute(X,[2 3 1]);
size(Y)
ans =
    2    1    5
  1. Output the rotated image to the screen as Figure 3 and label the output “Image Flipped XX” where XX indicates the selection by the user (vertical, horizonal, or diagonal).

  2. Publish ma4_ind_1_username.m as a PDF using one of the test cases and name it ma4_ind_1_username.pdf.

  3. Submit all of your deliverables to Gradescope.

Example Outputs:

../../../../../_images/block.svg

Fig. 15.1 The original downloadable image.#

../../../../../_images/block_vert.svg

Fig. 15.2 The image flipped vertically.#

../../../../../_images/block_horiz.svg

Fig. 15.3 The image flipped horizontally.#

../../../../../_images/block_diag.svg

Fig. 15.4 The image flipped diagonally.#