solution

Step 0:

inFile <- open input file from args
outFile1, outFile2 <- open from args
numRows, numCols, minVal, maxVal?- read from inFile HoughAngle <- 180
HoughDist <- 2 * (the diagonal of the input image)

imgAry?dynamically allocate

HoughAry <- dynamically allocate HoughAry, size of

HoughDist by HoughAngle and initialize to zero

Step 1: loadImage (inFile)
Step 2: buildHoughSpace (…) // See algorithm below.
Step 3: prettyPrint (HoughAry, outFile1)
Step 4: determineMinMax (HoughAry)
Step 5: outFile2?HoughDist, HoughAngle, HoughMinVal, HoughMaxVal to outFile2

// as the header of Hough image
step 6: ary2File (HoughAry, outFile2) // output HoughAry to outFile2

Step 7: close all files

*******************************
IV. buildHoughSpace (…) *******************************
Step 1: scan imgAry left to right and top to bottom

Using x for rows and y for column Step 2: imgAry (x, y)?next pixel
Step 3: if imgAry (x, y) > 0

computeSinusoid (x, y)
Step 4: repeat step 2 to step 3 until all pixels are processed

***************************************

*******************************
IV. buildHoughSpace (…)

*******************************
Step 1: scan imgAry left to right and top to bottom

Using x for rows and y for column

Step 2: imgAry (x, y) <- next pixel
Step 3: if imgAry (x, y) > 0

computeSinusoid (x, y)
Step 4: repeat step 2 to step 3 until all pixels are processed

***************************************

V. computeSinusoid (x, y)

****************************************

Step 1: angleInDegree <- 0

Step 2: angleInRadians <- angleInDegree / 180.00 * pi

Step 3: dist <- polarDistance (x, y, angleInRadians)

Step 4: distInt <- (int) dist // cast dist from double to int

Step 5: HoughAry[distInt][angleInDegree]++

Step 6: angleInDegree ++
step 7: repeat step 2 to Step 6 while angleInDegree <= 179

CODE::

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

import java.util.Scanner;

import java.lang.*;

public class CV_Project7

{

public static void main(String[] args) throws IOException

{

String file1 = “/Users/test3/img1.txt”;

FileReader inputReader = null;

BufferedReader buffInReader = null;

Scanner input = null;

String outFile2 = “/Users/test3/OutFile1.txt”;

FileWriter outputWriter = null;

BufferedWriter output = null;

try

{

inputReader = new FileReader(file1);

buffInReader = new BufferedReader(inputReader);

input = new Scanner(buffInReader);

int numRows = 0 ;

if( input.hasNextInt() ) numRows = input.nextInt() ;

int numCols = 0 ;

if( input.hasNextInt() ) numCols = input.nextInt() ;

int minVal = 0 ;

if( input.hasNextInt() ) minVal = input.nextInt() ;

int maxVal = 0 ;

if( input.hasNextInt() ) maxVal = input.nextInt() ;

Reader readObj = new Reader(numRows,numCols,minVal,maxVal ) ;

for(int i = 0; i < numRows; i++)

{

for(int j = 0; j < numCols; j++)

{

if(input.hasNextInt())

{

readObj.body[i][j] = input.nextInt();

}

}

}

int[][] imgAry = new int[numRows][numCols];

for(int i = 0; i < numRows; i++)

{

for(int j = 0; j < numCols; j++)

{

imgAry[i][j] = (readObj.body[i][j]);

}

}

int houghAngle = 180;

double diagonal = Math.ceil((Math.sqrt((numRows * numRows) + (numCols * numCols))));

int houghDist = (int) diagonal * 2;

buildHoughSpace(file1, readObj, imgAry, diagonal);

}

finally

{

if( input != null ) input.close();

if( output != null ) output.close();

}

System.out.println(“Done”);

}

public static void buildHoughSpace(String file, Reader readObj, int[][] imgAry, double diagonal)

{

for(int i = 0; i < readObj.numRows; i++)

{

for(int j = 0; j < readObj.numCols; j++)

{

if((imgAry[i][j]) > 0)

{

computeSinusoid(i, j);

}

}

}

}

public static void computeSinusoid(int i, int j)

{

int angleInDegree = 0;

double angleInRadian = Math.toRadians(angleInDegree);

double dist = polarDistance(i, j, angleInRadian);

int distInt = (int) dist;

int[][] houghAry = new int[distInt][angleInDegree];

for(int x = 0; x < i ; i++)

{

for(int y = 0; y < j; y++)

{

while(angleInDegree <= 179)

{

houghAry[distInt][angleInDegree]++;

angleInDegree++;

}

}

}

}

public static double polarDistance(int i, int j, double angle)

{

double x = i;

double y = j;

double rad = Math.toRadians(angle);

System.out.println(rad);

double offset = Math.sqrt((i*i)+(j*j));

double p = (x*Math.cos(rad)) + (y*Math.sin(rad) + offset);

return p;

}

}

Input text file can be:

3 3 0 1

0 0 0

0 1 0

0 0 0

 
"Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"
Looking for a Similar Assignment? Our Experts can help. Use the coupon code SAVE30 to get your first order at 30% off!

Hi there! Click one of our representatives below and we will get back to you as soon as possible.

Chat with us on WhatsApp