Esempio n. 1
0
/**
 * Performs the image segmentation using the "Heuristic for Minimum Spanning
 * Forests" algorithm. It uses the weightfn to compute the weight of the
 * graph edges. minWeight is the only parameter.
 * For more information on this algorithm refer to either my report which link
 * is on the repo's README or to:
 * http://algo2.iti.kit.edu/wassenberg/wassenberg09parallelSegmentation.pdf
 */
func (s *Segmenter) SegmentHMSF(sigmaSmooth, minWeight float64) {
	start := time.Now()
	sigma := imagenoise.EstimateStdev(s.img)
	s.smoothImage(sigmaSmooth)
	s.buildGraph()

	fmt.Printf("segment... ")
	start = time.Now()
	s.resultset = disjointset.New(s.graph.TotalVertices())

	edges := s.graph.Edges()
	sort.Sort(edges)
	setll := s.hmsfMergeEdgesByWeight(edges, minWeight)
	regionCredit := s.hmsfComputeCredit(setll, sigma)
	s.hmsfMergeRegionsByCredit(edges, regionCredit)
	regionCredit[0] = 1
	fmt.Println(time.Since(start))
	fmt.Println("Components:", s.resultset.Components())
}
Esempio n. 2
0
/**
 * Performs the image segmentation using the "Graph Based Segmentation"
 * algorithm. It uses sigma to apply a gaussian filter with it to the image
 * to smooth it before running the algorithm.
 * k and minSize are the algorithm parameters. For more information on this
 * algorithm refer to either my report which link is on the repo's README or
 * to: http://cs.brown.edu/~pff/papers/seg-ijcv.pdf
 */
func (s *Segmenter) SegmentGBS(sigma, k float64, minSize int) {
	s.smoothImage(sigma)
	s.buildGraph()
	fmt.Printf("segment... ")
	start := time.Now()
	s.resultset = disjointset.New(s.graph.TotalVertices())
	threshold_vals := make([]float64, s.graph.TotalVertices(), s.graph.TotalVertices())

	for v := 0; v < s.graph.TotalVertices(); v++ {
		threshold_vals[v] = k
	}

	edges := s.graph.Edges()
	sort.Sort(edges)

	s.gbsMergeFromThreshold(edges, threshold_vals, k)
	s.gbsMergeSmallRegions(edges, minSize)

	fmt.Println(time.Since(start))
	fmt.Println("Components:", s.resultset.Components())
}