I am trying to find the longest branch in a skeleton image and show the final image as an output but stuck into the algorithm. Right now I am able to find a line and draw it in the output. but I need to find the longest line. This is what I've done so far:
var vect1= new scala.collection.mutable.ArrayBuffer[Point]()
var p=new Point (0,0)
var res = new Array[Byte](1)
var u=skel.get(p.x.toInt,p.y.toInt,res)
var value1: Int=0
var value2: Int=0
scala.util.control.Breaks.breakable {
while((value1 < skel.rows ) ){
while ( (value2 < skel.cols )){
if (res(0) == -1) {
p.x=(p.x.toInt)+value1
p.y=(p.y.toInt)+value2
scala.util.control.Breaks.break()
}
value2=value2+1
skel.get(value1,value2,res)
}
value2=0
value1=value1+1
}
}
vect1 = traceLine(skel, p);
//inside traceLine the algorithm makes a vector and looks for 8 neighbors around the point to find the next available point and make the vector then return the result and save it into vect1.
val output= new Mat (skel.rows, skel.cols, CvType.CV_8UC3,new Scalar(0, 0, 0))
val it = vect1.iterator //Iterator(vect1)
var vect3=new Array[Byte](3)
vect3(0)=0
vect3(1)=255.toByte
vect3(2)=0
vect1.foreach(p => output.put(p.x.toInt, p.y.toInt, vect3))
Question is how can I return the longest branch?