Hough transform: Difference between revisions

Scala improved
m (separated comment from a task directive.)
(Scala improved)
Line 675:
val inputData = readDataFromImage(args(0))
val minContrast = if (args.length >= 4) 64 else args(4).toInt
val outputData = inputData(args(2).toInt, args(3).toInt, minContrast).writeOutputImage(args(1))
outputData.writeOutputImage(args(1))
}
 
Line 695 ⟶ 694:
}
 
class ArrayData(val dataArray: Array[Int], val width: Int, val height: Int) {
def this(width: Int, height: Int) {
this(Array.ofDim[Int](width * height), width, height)
}
 
def get(x: Int, y: Int) = dataArray(y * width + x)
 
def update(x: Int, y: Int, value: Int) {
dataArray(y * width + x)(y) = value
}
 
Line 722 ⟶ 715:
val r = cosTable(theta) * x + sinTable(theta) * y
val rScaled = Math.round(r * halfRAxisSize / maxRadius).toInt + halfRAxisSize
outputData.accumulatedataArray(theta, )(rScaled,) += 1)
}
 
Line 729 ⟶ 722:
 
def writeOutputImage(filename: String) {
valvar max = dataArrayInt.maxMinValue
for (y <- 0 until height; x <- 0 until width) {
val v = dataArray(x)(y)
if (v > max) max = v
}
val image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB)
for (y <- 0 until height; x <- 0 until width) {
val n = Math.min(Math.round(getdataArray(x, )(y) * 255.0 / max).toInt, 255)
image.setRGB(x, height - 1 - y, (n << 16) | (n << 8) | 0x90 | -0x01000000)
}
ImageIO.write(image, "PNG", new File(filename))
}
 
private def accumulate(x: Int, y: Int, delta: Int) {
update(x, y, get(x, y) + delta)
}
 
private def contrast(x: Int, y: Int, minContrast: Int): Boolean = {
val centerValue = getdataArray(x, )(y)
for (i <- 8 until -1 by -1 if i != 4) {
val newx = x + (i % 3) - 1
val newy = y + (i / 3) - 1
if (newx >= 0 && newx < width && newy >= 0 && newy < height &&
Math.abs(getdataArray(newx, )(newy) - centerValue) >= minContrast)
return true
}
Line 754 ⟶ 747:
false
}
 
private val dataArray = this(Array.ofDim[Int](width * height), width, height)
}</lang>
 
Anonymous user