public ArrayData houghTransform(ArrayData originalImage, int thetaAxisSize, int rAxisSize, int minContrast) { int width = originalImage.width; int height = originalImage.height; int maxRadius = (int)Math.Ceiling(hypotenuse(width, height)); int halfRAxisSize = rAxisSize >> 1; var outputImage = 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 (originalImage.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; outputImage.accumulate(theta, rScaled, 1); } } } } return(outputImage); }
public ArrayData houghTransform(ArrayData originalImage, int thetaAxisSize, int rAxisSize, int minContrast) { int width = originalImage.width; int height = originalImage.height; int maxRadius = (int)Math.Ceiling(hypotenuse(width, height)); int halfRAxisSize = rAxisSize >> 1; var outputImage = 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 (originalImage.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; outputImage.accumulate(theta, rScaled, 1); } } } } return outputImage; }