Introduction to MATLAB Programming
19 Questions
4 Views

Introduction to MATLAB Programming

Created by
@DeliciousPlanet4724

Podcast Beta

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the purpose of using the imopen function in image processing?

  • To convert an image to binary format
  • To emphasize dark text in an image (correct)
  • To apply a bottom hat transformation
  • To enhance bright text in an image
  • Which operation is performed to restore the original order of intensities after subtraction?

  • Thresholding the image
  • Inversion using the operator '~' (correct)
  • Binarization using `imbinarize()`
  • Performing a top hat transform
  • What does the bottom hat transform accomplish in image processing?

  • It closes an image and subtracts the original image from the closed image (correct)
  • It suppresses background regions and highlights dark text
  • It brightens the whole image
  • It emphasizes bright features by adding noise
  • What is meant by 'minima should not be found in non-receipt images'?

    <p>Non-receipt images should not exhibit any local minima</p> Signup and view all the answers

    Why is adaptive thresholding not necessary with good preprocessing?

    <p>Good preprocessing creates high-contrast images suitable for basic thresholding</p> Signup and view all the answers

    What is the primary purpose of the command 'imshow' in MATLAB?

    <p>To display image data stored in a variable</p> Signup and view all the answers

    What is the default behavior of the 'imbinarize' function with respect to image foreground and background?

    <p>Assumes the foreground is bright and the background is dark</p> Signup and view all the answers

    Which command in MATLAB is used to convert an image to grayscale?

    <p>im2gray</p> Signup and view all the answers

    What is the effect of adding a semicolon at the end of a command in MATLAB?

    <p>It allows the command to execute silently without displaying output</p> Signup and view all the answers

    Which command can you use in MATLAB to find the maximum value in an array?

    <p>max(variable,[], 'all')</p> Signup and view all the answers

    What does the 'fspecial' function with input 'average' do in MATLAB?

    <p>Creates an averaging filter for noise reduction</p> Signup and view all the answers

    Which of the following best describes the 'command window' in MATLAB?

    <p>Where commands are typed and executed one by one</p> Signup and view all the answers

    What does the command 'imfilter' do in MATLAB?

    <p>It applies a specified filter to an image</p> Signup and view all the answers

    What is the output of the 'size' function when applied to an RGB image?

    <p>Returns a vector with three elements for height, width, and color planes</p> Signup and view all the answers

    What is the purpose of the 'imshowpair' function in MATLAB?

    <p>To display two images in a side-by-side format</p> Signup and view all the answers

    How can the 'imlocalbrighten' function be utilized in MATLAB?

    <p>To automatically adjust the contrast of colored images</p> Signup and view all the answers

    What is the correct way to execute a script in MATLAB once it is saved in the current directory?

    <p>By typing the script's name at the command prompt</p> Signup and view all the answers

    Which of the following best describes the function 'imhist'?

    <p>It generates an intensity histogram to analyze contrast</p> Signup and view all the answers

    What is the function of the 'imclose' command with a structuring element?

    <p>To connect brighter background regions and remove thin dark letters</p> Signup and view all the answers

    Study Notes

    MATLAB

    • High-level technical computing language with a user-friendly interface.
    • Name comes from MATrix and LABoratory, emphasizing its matrix-based operations.
    • Developed by Mathworks, first released in 1984.

    ###  MATLAB Application Fields 

    • Control engineering
    • Applied mathematics
    • Science and engineering disciplines

    MATLAB Working Environment 

    • Command Window: The main window where commands are entered and results are displayed.
    • Command Prompt: The area where users type commands.
    • Command History Window: Shows previously executed commands.
    • Current Directory: Located in the lower left, specifying the current active folder in MATLAB, which is the working folder.

    Working with MATLAB

    • Command Window: Executes commands one by one
    • Text Editor: Used to write sequences of commands, called scripts, for batch processing.
      • Scripts are executed directly from the editor window using the "Debug - Run" option or by typing the script's name in the command prompt.
      • Scripts must be saved in the current directory.
      • Scripts, along with functions, are collectively called M-Files

    Functions in MATLAB

    • imread("filename"): Imports an image into memory and assigns it to a variable.
    • imshow(variablename): Displays image data stored in a variable.
    • imshowpair(variable, variable, "montage"): Displays two images side by side.
    • imwrite(variable, "name"): Exports data stored in MATLAB into an image file. The output format is automatically identified based on the file extension.
    • size(variable): Finds the size of an array (image), returning a vector:
      • First element: Represents the number of rows (height).
      • Second element: Represents the number of columns (width).
      • Third element: Represents the third dimension of the array (RGB color planes).
    • I(num, num, num): Used for extracting RGB color planes.
    • max(variable, [], "all"): Finds the largest value in an array, across all values.
    • min(variable, [], "all"): Finds the smallest value in an array.
    • [R, G, B] = imsplit("variable"): Extracts all three color planes of an image array.
    • montage({R, G, B}): Displays all three color planes using montage.

    Definitions

    • Semicolon (;): Ending a command with a semicolon prevents MATLAB from displaying the values stored in a variable.
    • Images: Contain millions of values.
    • Run / Run Section: Used to execute scripts, located in the MATLAB Toolstrip.
    • Unsigned 8-bit integer (uint8): Used by most images, storing integers from 0 to 255.
      • Bright colors are represented by values closer to 255.
      • Dark areas are signified by values closer to 0.

    Functions in MATLAB

    • im2gray(variable): Converts an image to grayscale, resulting in a two-dimensional array.
      • Grayscale images have a single plane of intensity values.
      • Intensity values are computed as a weighted sum of RGB planes.
    • imhist(variable): Investigates the contrast of an image by generating an intensity histogram.
      • Pixels binned at high and low ends suggest good contrast.
      • Dark pixels have intensity values around 100.
      • Bright pixels rarely have intensity values above 200.
      • Contrast is considered half of its potential if the image doesn't use the full intensity range (0 - 255).
        • Increasing contrast brightens bright pixels and darkens dark pixels.
    • imadjust(variable): Automatically adjusts the contrast of a grayscale image.
      • Only works for grayscale images unless additional input is provided.
    • imlocalbrighten(variable): Adjusts the contrast of colored images.

    Definitions

    • Purple values: Unhelpful in classification algorithms.
    • Text: An essential identifying feature for receipts.
      • Receipt images should have good contrast for the text to stand out.
    • Logical operators (>, <): Generate arrays of the same size containing logical values (1 or 0).
    • Logical operators: Can be used to threshold intensity values in a grayscale image, creating a binary image.
      • Use a threshold just below the peak to achieve better segmentation.

    Functions in MATLAB

    • imbinarize(variable): Automates the threshold selection process, calculating the "best" threshold.
      • By default, uses a global threshold, applying the same threshold to every pixel.
      • "Adaptive" option: Uses smaller regions and picks the best threshold for each region.
        • imbinarize(variable, "adaptive")
      • By default, assumes the foreground is bright and the background is dark, which is opposite for receipts.
      • "ForegroundPolarity": Specifies whether the foreground is bright or dark:
        • imbinarize(variable, "adaptive", "ForegroundPolarity", "dark")
      • Binary mask: Can be applied to images to analyze their contents, helpful for image processing problems.
    • sum(variable, 2): Computes the sums across rows of an array by operating along the second dimension. Used to get the rowsum.
      • A distinctive pattern in the rowsum signal (alternating higher sums - blank whitespace, lower sums - rows of text) indicates the presence of text. This pattern is absent in text-less images.
    • plot(variable): Plots the rowsum.

    Functions in MATLAB

    • fspecial("average", n): Creates an n-by-n averaging filter to reduce the impact of noise in a binary image.
    • imfilter(image variable, averaging filter variable): Applies a filter to an image.
      • It's advisable to filter before binarizing the image.
      • The default setting sets pixels outside the image to zero, creating unwanted dark outlines.
      • imfilter(image variable, averaging filter variable, "replicate"): Uses pixel intensity values on the image border for pixels outside the image, removing artificial borders.

    Definitions

    • Some receipt images have elements that distort the text pattern's oscillations.
    • Noise: Its removal enhances the prominence of text. Noise can interfere with receipt identification by polluting regions in a binarized image.
    • Images taken in low light: Noisy because of increased camera sensitivity.

    Functions in MATLAB

    • strel("diamond", 5): Creates a structuring element.
      • This code defines a diamond-shaped structuring element with a radius of 5 pixels.
      • Disk and rectangle elements can also be created.
    • imclose(variable, structuring): Performs a closing operation with the structuring element.
      • Emphasizes and connects the brighter background, removing thin dark lettering, while larger background objects like thumbs remain.
      • The final result is an image of the background without the text.
      • Isolates the background for subtraction later.
      • Subtracting a higher intensity variable from a lower one results in negative intensities. (Gs - Ibg)
      • To obtain positive intensities, subtract the lower intensity variable from the higher variable. (Ibg - Gs)
      • The earlier subtraction inverts the intensities. To fix this and restore the original order, use the inversion operator "~."
      • Generate a binary image using imbinarize and then invert it using "~imbinarize()."
    • imbothat(variable, structuring): Performs a bottom hat transform.
    • imopen(variable, structuring): Emphasizes dark text instead of bright text, opposite of imclose.
      • Using this with a rectangle structuring element transforms lines of text into black horizontal stripes, enhancing the valleys.

    Definitions

    • Background: In a receipt image, anything that's not text.
    • Adaptive threshold is not needed with good preprocessing.
    • Bottom hat transform: Closing an image, then subtracting the original image from the closed image.

    Functions in MATLAB

    • Oscillations: Contain peak regions (white space) and valley regions (text).
    • Find Local Extrema live task: Identifies local minima or maxima in a signal automatically.
      • Set the input data to "S" and the extrema type to "Minima".
      • In the default setting, it identifies many shallow minima that don't correspond to rows of text.

    Definitions

    • Minima should not be found in non-receipt images.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    dsp-lab-reviewer.docx

    Description

    This quiz covers the basics of MATLAB, including its history, application fields, and the main components of the working environment. Understand how to use the Command Window, Command Prompt, and the Text Editor for effective programming in MATLAB.

    More Like This

    MATLAB Programming Overview
    10 questions
    Introduction to MATLAB Programming
    12 questions
    Use Quizgecko on...
    Browser
    Browser