Question

Describe Hough Transform algorithm for line detection. Explain parameter space. Give the steps on the algorithm....

Describe Hough Transform algorithm for line detection. Explain parameter space. Give the steps on the algorithm. Suggest two implementations: (a) using edge point locations only, (b) using edge location and edge direction information.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The Hough Transform is a global method for finding straight lines (functions) hidden in larger amounts of other data. It is an important technique in image processing. For detecting lines in images, the image is first binarised using some form of thresholding and then the positive instances catalogued in an examples dataset.

To understand the Hough Transform, it is important to know what the Hough space is. Each point (d,T) in Hough space corresponds to a line at angle T and distance d from the origin in the original data space. This is a parametrization. The value of a function in Hough space gives the point density along a line in the data space. The Hough Transform utilises this by the following method.

For each point in the original space consider all the lines which go through that point at a particular discrete set of angles, chosen a priori. For each angle T, calculate the distance to the line through the point at that angle and discretise that distance using an a priori chosen discretisation, giving value d.

Make a corresponding discretisation of the Hough space - this will result in a set of boxes in Hough space. These boxes are called the Hough accumulators. For each line we consider above, we increment a count (initialised at zero) in the Hough accumulator at point (d,T). After considering all the lines through all the points, a Hough accumulator with a high value will probably correspond to a line of points.

Width% = 320
      Height% = 240
 
      VDU 23,22,Width%;Height%;8,16,16,128
      *DISPLAY Pentagon.bmp
      OFF
 
      DIM hist%(Width%-1, Height%-1)
 
      rs = 2 * SQR(Width%^2 + Height%^2) / Height% : REM Radial step
      ts = PI / Width% : REM Angular step
      h% = Height% / 2
 
      REM Hough transform:
      FOR y% = 0 TO Height%-1
        FOR x% = 0 TO Width%-1
          IF TINT(x%*2, y%*2) = 0 THEN
            FOR t% = 0 TO Width%-1
              th = t% * ts
              r% = (x%*COS(th) + y%*SIN(th)) / rs + h% + 0.5
              hist%(t%,r%) += 1
            NEXT
          ENDIF
        NEXT
      NEXT y%
 
      REM Find max:
      max% = 0
      FOR y% = 0 TO Height%-1
        FOR x% = 0 TO Width%-1
          IF hist%(x%,y%) > max% max% = hist%(x%,y%)
        NEXT
      NEXT y%
 
      REM Plot:
      GCOL 1
      FOR y% = 0 TO Height%-1
        FOR x% = 0 TO Width%-1
          c% = 255 * hist%(x%,y%) / max%
          COLOUR 1, c%, c%, c%
          LINE x%*2,y%*2,x%*2,y%*2
        NEXT
      NEXT y%
 
      REPEAT
        WAIT 1
      UNTIL FALSE
import java.awt.image.*;
import java.io.File;
import java.io.IOException;
import javax.imageio.*;
 
public class HoughTransform
{
  public static ArrayData houghTransform(ArrayData inputData, int thetaAxisSize, int rAxisSize, int minContrast)
  {
    int width = inputData.width;
    int height = inputData.height;
    int maxRadius = (int)Math.ceil(Math.hypot(width, height));
    int halfRAxisSize = rAxisSize >>> 1;
    ArrayData outputData = new ArrayData(thetaAxisSize, rAxisSize);
    // x output ranges from 0 to pi
    // y output ranges from -maxRadius to maxRadius
    double[] sinTable = new double[thetaAxisSize];
    double[] cosTable = new double[thetaAxisSize];
    for (int theta = thetaAxisSize - 1; theta >= 0; theta--)
    {
      double thetaRadians = theta * Math.PI / thetaAxisSize;
      sinTable[theta] = Math.sin(thetaRadians);
      cosTable[theta] = Math.cos(thetaRadians);
    }
 
    for (int y = height - 1; y >= 0; y--)
    {
      for (int x = width - 1; x >= 0; x--)
      {
        if (inputData.contrast(x, y, minContrast))
        {
          for (int theta = thetaAxisSize - 1; theta >= 0; theta--)
          {
            double r = cosTable[theta] * x + sinTable[theta] * y;
            int rScaled = (int)Math.round(r * halfRAxisSize / maxRadius) + halfRAxisSize;
            outputData.accumulate(theta, rScaled, 1);
          }
        }
      }
    }
    return outputData;
  }
 
  public static class ArrayData
  {
    public final int[] dataArray;
    public final int width;
    public final int height;
 
    public ArrayData(int width, int height)
    {
      this(new int[width * height], width, height);
    }
 
    public ArrayData(int[] dataArray, int width, int height)
    {
      this.dataArray = dataArray;
      this.width = width;
      this.height = height;
    }
 
    public int get(int x, int y)
    {  return dataArray[y * width + x];  }
 
    public void set(int x, int y, int value)
    {  dataArray[y * width + x] = value;  }
 
    public void accumulate(int x, int y, int delta)
    {  set(x, y, get(x, y) + delta);  }
 
    public boolean contrast(int x, int y, int minContrast)
    {
      int centerValue = get(x, y);
      for (int i = 8; i >= 0; i--)
      {
        if (i == 4)
          continue;
        int newx = x + (i % 3) - 1;
        int newy = y + (i / 3) - 1;
        if ((newx < 0) || (newx >= width) || (newy < 0) || (newy >= height))
          continue;
        if (Math.abs(get(newx, newy) - centerValue) >= minContrast)
          return true;
      }
      return false;
    }
 
    public int getMax()
    {
      int max = dataArray[0];
      for (int i = width * height - 1; i > 0; i--)
        if (dataArray[i] > max)
          max = dataArray[i];
      return max;
    }
  }
 
  public static ArrayData getArrayDataFromImage(String filename) throws IOException
  {
    BufferedImage inputImage = ImageIO.read(new File(filename));
    int width = inputImage.getWidth();
    int height = inputImage.getHeight();
    int[] rgbData = inputImage.getRGB(0, 0, width, height, null, 0, width);
    ArrayData arrayData = new ArrayData(width, height);
    // Flip y axis when reading image
    for (int y = 0; y < height; y++)
    {
      for (int x = 0; x < width; x++)
      {
        int rgbValue = rgbData[y * width + x];
        rgbValue = (int)(((rgbValue & 0xFF0000) >>> 16) * 0.30 + ((rgbValue & 0xFF00) >>> 8) * 0.59 + (rgbValue & 0xFF) * 0.11);
        arrayData.set(x, height - 1 - y, rgbValue);
      }
    }
    return arrayData;
  }
 
  public static void writeOutputImage(String filename, ArrayData arrayData) throws IOException
  {
    int max = arrayData.getMax();
    BufferedImage outputImage = new BufferedImage(arrayData.width, arrayData.height, BufferedImage.TYPE_INT_ARGB);
    for (int y = 0; y < arrayData.height; y++)
    {
      for (int x = 0; x < arrayData.width; x++)
      {
        int n = Math.min((int)Math.round(arrayData.get(x, y) * 255.0 / max), 255);
        outputImage.setRGB(x, arrayData.height - 1 - y, (n << 16) | (n << 8) | 0x90 | -0x01000000);
      }
    }
    ImageIO.write(outputImage, "PNG", new File(filename));
    return;
  }
 
  public static void main(String[] args) throws IOException
  {
    ArrayData inputData = getArrayDataFromImage(args[0]);
    int minContrast = (args.length >= 4) ? 64 : Integer.parseInt(args[4]);
    ArrayData outputData = houghTransform(inputData, Integer.parseInt(args[2]), Integer.parseInt(args[3]), minContrast);
    writeOutputImage(args[1], outputData);
    return;
  }
}
Add a comment
Know the answer?
Add Answer to:
Describe Hough Transform algorithm for line detection. Explain parameter space. Give the steps on the algorithm....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • When asked to describe an algorithm you are expected to give a clear pseudo-code description of...

    When asked to describe an algorithm you are expected to give a clear pseudo-code description of the algorithm 1. (10 pts) Here is a new sorting algorithm NewSort Suppose the original call made is NewSort(A,0,n-1) where A is an array integers. == void NewSort(int A[], int i, int j){ \\ sorts the subarray Aſi..j] if (j i+1) \\when there are only 2 elements if (A[i] > A[j]) swap(A,i,j) \\swaps A[i] and A[j] else { int k = (j-i+1)/3; NewSort(A,i,j-k); \\...

  • Maxwell's equations can be used to show that electromagnetic waves can propagate through space (a) Describe the key aspects of an electromagnetic wave. Your description should mention the electri...

    Maxwell's equations can be used to show that electromagnetic waves can propagate through space (a) Describe the key aspects of an electromagnetic wave. Your description should mention the electric and magnetic fields, direction of propagation, and speed. A diagram would be useful in explaining these concepts (b) At some point in space, a sinusoidal electromagnetic wave has an intensity of 2.5 Wm2 Calculate the amplitudes of the electric field and the magnetic field at this point. Ensure that you include...

  • Please complete all steps and explain as thoroughly as possible for the best possible rating. Power...

    Please complete all steps and explain as thoroughly as possible for the best possible rating. Power lines produce both electric and magnetic fields. The interior of the human body is an electrical conductor, and as a result, electric fields are greatly reduced in magnitude within the body The electric fields inside the body from are much smaller than electric fields normally existing in the body However, magnetic fields are not reduced in the body. Earth's magnetic field, approximately 5 ×...

  • 1. A. Name the three planes and the positions they each describe to identify a unique...

    1. A. Name the three planes and the positions they each describe to identify a unique position in the human body. B. Name the two major ventral body cavities plus the major organs found in them. C. Name the cavities that the heart and lungs reside in. D. Finally, list the six levels of organization in nature. 2. A. Describe the three components of an atom in terms of charge and location. Define atomic mass and atomic number. B. For...

  • III. Mapping the Field Around a Bar Magnet: An Observation Experiment Purposes: Design an experiment to take approp...

    III. Mapping the Field Around a Bar Magnet: An Observation Experiment Purposes: Design an experiment to take appropriate data to find a relationship. Construct a mathematical model to describe that relationship Description: Your task is to use a compass to map the magnetic field of a small magnet. Construct a circle of radius 10 cm on a clean sheet of paper, and mark points on the circle every 30°. Place the bar magnet so that its center is resting at...

  • Write a c++ program in that file to perform a “Search and Replace All” operation. This...

    Write a c++ program in that file to perform a “Search and Replace All” operation. This operation consists of performing a case-sensitive search for all occurrences of an arbitrary sequence of characters within a file and substituting another arbitrary sequence in place of them. Please note: One of the biggest problems some students have with this exercise occurs simply because they don’t read the command line information in the course document titled “Using the Compiler’s IDE”. Your program: 1. must...

  • Electric Fields Equipment and Setup: Mathematica file- ElectricFields.nb Section A: Electric Fields Due to Two Charges...

    Electric Fields Equipment and Setup: Mathematica file- ElectricFields.nb Section A: Electric Fields Due to Two Charges Computer Setup for Section A 1. The first interactive panel shows electric fields due to two point charges, Qat (-1 m,0) and Q, at (1 m,0). The controls for this panel are at the top on the left 2. The top line has two checkboxes: one to Show Axes and the other to Show Field Lines. The top line also has a slider labeled...

  • Explain what enterprise resource planning (ERP) systems. Outline several of their key characteristics. Describe in reasonable...

    Explain what enterprise resource planning (ERP) systems. Outline several of their key characteristics. Describe in reasonable detail how a company leverages an ERP system and how its operations are improved after installing an ERP system like SAP. Explain how a supply chain management system helps an organization make its operations more efficient What is Upstream and Downstream management of the supply chain? Explain the concept of “Supply Network”, its benefits, and how technology made this concept available Explain the difference...

  • Designing a High speed Wireless Data Link Line of Sight Link Budget Analysis Several major factors that can impact...

    Designing a High speed Wireless Data Link Line of Sight Link Budget Analysis Several major factors that can impact the performance of a radio system are Available/permitted output power e Bandwidth, . Receiver sensitivity Antenna gains In this case study, the students will be required to calculate the link budget for a LOS Wireless link. Read through the following to understand some of the aspects and elements that need to be considered when calculating a Link Budget. If the estimated/calculated...

  • Exercise #1: Write a C program that contains the following steps (make sure all variables are...

    Exercise #1: Write a C program that contains the following steps (make sure all variables are int). Read carefully each step as they are not only programming steps but also learning topics that explain how functions in C really work. Ask the user for a number between 10 and 99. Write an input validation loop to make sure it is within the prescribed range and ask again if not. Commenting out the existing coding, write the code to divide a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT