Question
import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.io.*; import javax.imageio.*; // Main class public class HoughTransform extends Frame implements ActionListener { BufferedImage input; int width,
import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.io.*; import javax.imageio.*;
// Main class public class HoughTransform extends Frame implements ActionListener { BufferedImage input; int width, height, diagonal; ImageCanvas source, target; TextField texRad, texThres; // Constructor public HoughTransform(String name) { super("Hough Transform"); // load image try { input = ImageIO.read(new File(name)); } catch ( Exception ex ) { ex.printStackTrace(); } width = input.getWidth(); height = input.getHeight(); diagonal = (int)Math.sqrt(width * width + height * height); // prepare the panel for two images. Panel main = new Panel(); source = new ImageCanvas(input); target = new ImageCanvas(input); main.setLayout(new GridLayout(1, 2, 10, 10)); main.add(source); main.add(target); // prepare the panel for buttons. Panel controls = new Panel(); Button button = new Button("Line Transform"); button.addActionListener(this); controls.add(button); controls.add(new Label("Radius:")); texRad = new TextField("10", 3); controls.add(texRad); button = new Button("Circle Transform"); button.addActionListener(this); controls.add(button); controls.add(new Label("Threshold:")); texThres = new TextField("25", 3); controls.add(texThres); button = new Button("Search"); button.addActionListener(this); controls.add(button); // add two panels add("Center", main); add("South", controls); addWindowListener(new ExitListener()); setSize(diagonal*2+100, Math.max(height,360)+100); setVisible(true); } class ExitListener extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } } // Action listener public void actionPerformed(ActionEvent e) { // perform one of the Hough transforms if the button is clicked. if ( ((Button)e.getSource()).getLabel().equals("Line Transform") ) { int[][] g = new int[360][diagonal]; // insert your implementation for straight-line here. DisplayTransform(diagonal, 360, g); } else if ( ((Button)e.getSource()).getLabel().equals("Circle Transform") ) { int[][] g = new int[height][width]; int radius = Integer.parseInt(texRad.getText()); // insert your implementation for circle here. DisplayTransform(width, height, g); } } // display the spectrum of the transform. public void DisplayTransform(int wid, int hgt, int[][] g) { target.resetBuffer(wid, hgt); for ( int y=0, i=0 ; y
public static void main(String[] args) { new HoughTransform(args.length==1 ? args[0] : "rectangle.png"); } }
Objectives: In this assignment you will implement the straight-line and circle Hough transforms discussed in class. The goal is to give you a further understanding of Hough transform, as wel as the straight-line and circle detection problems. Your Task: You need to implement both straight line and circle Hough transforms. For straight-line only need to search for circles with a known radius, which is given by the user through a text field. Show detected lines and circles under user-specified threshold through plotting the corresponding shapes on the input image. Hough ansfo Line Transform Radius10 Circle Transform Threshold: 25 Search Objectives: In this assignment you will implement the straight-line and circle Hough transforms discussed in class. The goal is to give you a further understanding of Hough transform, as wel as the straight-line and circle detection problems. Your Task: You need to implement both straight line and circle Hough transforms. For straight-line only need to search for circles with a known radius, which is given by the user through a text field. Show detected lines and circles under user-specified threshold through plotting the corresponding shapes on the input image. Hough ansfo Line Transform Radius10 Circle Transform Threshold: 25 SearchStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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