|
Packit |
ea1746 |
// Ceres Solver - A fast non-linear least squares minimizer
|
|
Packit |
ea1746 |
// Copyright 2015 Google Inc. All rights reserved.
|
|
Packit |
ea1746 |
// http://ceres-solver.org/
|
|
Packit |
ea1746 |
//
|
|
Packit |
ea1746 |
// Redistribution and use in source and binary forms, with or without
|
|
Packit |
ea1746 |
// modification, are permitted provided that the following conditions are met:
|
|
Packit |
ea1746 |
//
|
|
Packit |
ea1746 |
// * Redistributions of source code must retain the above copyright notice,
|
|
Packit |
ea1746 |
// this list of conditions and the following disclaimer.
|
|
Packit |
ea1746 |
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
Packit |
ea1746 |
// this list of conditions and the following disclaimer in the documentation
|
|
Packit |
ea1746 |
// and/or other materials provided with the distribution.
|
|
Packit |
ea1746 |
// * Neither the name of Google Inc. nor the names of its contributors may be
|
|
Packit |
ea1746 |
// used to endorse or promote products derived from this software without
|
|
Packit |
ea1746 |
// specific prior written permission.
|
|
Packit |
ea1746 |
//
|
|
Packit |
ea1746 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Packit |
ea1746 |
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit |
ea1746 |
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
Packit |
ea1746 |
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
Packit |
ea1746 |
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
Packit |
ea1746 |
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
Packit |
ea1746 |
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
Packit |
ea1746 |
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
Packit |
ea1746 |
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
Packit |
ea1746 |
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
Packit |
ea1746 |
// POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
ea1746 |
//
|
|
Packit |
ea1746 |
// Author: sameeragarwal@google.com (Sameer Agarwal)
|
|
Packit |
ea1746 |
//
|
|
Packit |
ea1746 |
// An implementation of the Canonical Views clustering algorithm from
|
|
Packit |
ea1746 |
// "Scene Summarization for Online Image Collections", Ian Simon, Noah
|
|
Packit |
ea1746 |
// Snavely, Steven M. Seitz, ICCV 2007.
|
|
Packit |
ea1746 |
//
|
|
Packit |
ea1746 |
// More details can be found at
|
|
Packit |
ea1746 |
// http://grail.cs.washington.edu/projects/canonview/
|
|
Packit |
ea1746 |
//
|
|
Packit |
ea1746 |
// Ceres uses this algorithm to perform view clustering for
|
|
Packit |
ea1746 |
// constructing visibility based preconditioners.
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#ifndef CERES_INTERNAL_CANONICAL_VIEWS_CLUSTERING_H_
|
|
Packit |
ea1746 |
#define CERES_INTERNAL_CANONICAL_VIEWS_CLUSTERING_H_
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#include <vector>
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#include "ceres/collections_port.h"
|
|
Packit |
ea1746 |
#include "ceres/graph.h"
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
namespace ceres {
|
|
Packit |
ea1746 |
namespace internal {
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
struct CanonicalViewsClusteringOptions;
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
// Compute a partitioning of the vertices of the graph using the
|
|
Packit |
ea1746 |
// canonical views clustering algorithm.
|
|
Packit |
ea1746 |
//
|
|
Packit |
ea1746 |
// In the following we will use the terms vertices and views
|
|
Packit |
ea1746 |
// interchangably. Given a weighted Graph G(V,E), the canonical views
|
|
Packit |
ea1746 |
// of G are the the set of vertices that best "summarize" the content
|
|
Packit |
ea1746 |
// of the graph. If w_ij i s the weight connecting the vertex i to
|
|
Packit |
ea1746 |
// vertex j, and C is the set of canonical views. Then the objective
|
|
Packit |
ea1746 |
// of the canonical views algorithm is
|
|
Packit |
ea1746 |
//
|
|
Packit |
ea1746 |
// E[C] = sum_[i in V] max_[j in C] w_ij
|
|
Packit |
ea1746 |
// - size_penalty_weight * |C|
|
|
Packit |
ea1746 |
// - similarity_penalty_weight * sum_[i in C, j in C, j > i] w_ij
|
|
Packit |
ea1746 |
//
|
|
Packit |
ea1746 |
// alpha is the size penalty that penalizes large number of canonical
|
|
Packit |
ea1746 |
// views.
|
|
Packit |
ea1746 |
//
|
|
Packit |
ea1746 |
// beta is the similarity penalty that penalizes canonical views that
|
|
Packit |
ea1746 |
// are too similar to other canonical views.
|
|
Packit |
ea1746 |
//
|
|
Packit |
ea1746 |
// Thus the canonical views algorithm tries to find a canonical view
|
|
Packit |
ea1746 |
// for each vertex in the graph which best explains it, while trying
|
|
Packit |
ea1746 |
// to minimize the number of canonical views and the overlap between
|
|
Packit |
ea1746 |
// them.
|
|
Packit |
ea1746 |
//
|
|
Packit |
ea1746 |
// We further augment the above objective function by allowing for per
|
|
Packit |
ea1746 |
// vertex weights, higher weights indicating a higher preference for
|
|
Packit |
ea1746 |
// being chosen as a canonical view. Thus if w_i is the vertex weight
|
|
Packit |
ea1746 |
// for vertex i, the objective function is then
|
|
Packit |
ea1746 |
//
|
|
Packit |
ea1746 |
// E[C] = sum_[i in V] max_[j in C] w_ij
|
|
Packit |
ea1746 |
// - size_penalty_weight * |C|
|
|
Packit |
ea1746 |
// - similarity_penalty_weight * sum_[i in C, j in C, j > i] w_ij
|
|
Packit |
ea1746 |
// + view_score_weight * sum_[i in C] w_i
|
|
Packit |
ea1746 |
//
|
|
Packit |
ea1746 |
// centers will contain the vertices that are the identified
|
|
Packit |
ea1746 |
// as the canonical views/cluster centers, and membership is a map
|
|
Packit |
ea1746 |
// from vertices to cluster_ids. The i^th cluster center corresponds
|
|
Packit |
ea1746 |
// to the i^th cluster.
|
|
Packit |
ea1746 |
//
|
|
Packit |
ea1746 |
// It is possible depending on the configuration of the clustering
|
|
Packit |
ea1746 |
// algorithm that some of the vertices may not be assigned to any
|
|
Packit |
ea1746 |
// cluster. In this case they are assigned to a cluster with id = -1;
|
|
Packit |
ea1746 |
void ComputeCanonicalViewsClustering(
|
|
Packit |
ea1746 |
const CanonicalViewsClusteringOptions& options,
|
|
Packit |
ea1746 |
const WeightedGraph<int>& graph,
|
|
Packit |
ea1746 |
std::vector<int>* centers,
|
|
Packit |
ea1746 |
HashMap<int, int>* membership);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
struct CanonicalViewsClusteringOptions {
|
|
Packit |
ea1746 |
CanonicalViewsClusteringOptions()
|
|
Packit |
ea1746 |
: min_views(3),
|
|
Packit |
ea1746 |
size_penalty_weight(5.75),
|
|
Packit |
ea1746 |
similarity_penalty_weight(100.0),
|
|
Packit |
ea1746 |
view_score_weight(0.0) {
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
// The minimum number of canonical views to compute.
|
|
Packit |
ea1746 |
int min_views;
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
// Penalty weight for the number of canonical views. A higher
|
|
Packit |
ea1746 |
// number will result in fewer canonical views.
|
|
Packit |
ea1746 |
double size_penalty_weight;
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
// Penalty weight for the diversity (orthogonality) of the
|
|
Packit |
ea1746 |
// canonical views. A higher number will encourage less similar
|
|
Packit |
ea1746 |
// canonical views.
|
|
Packit |
ea1746 |
double similarity_penalty_weight;
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
// Weight for per-view scores. Lower weight places less
|
|
Packit |
ea1746 |
// confidence in the view scores.
|
|
Packit |
ea1746 |
double view_score_weight;
|
|
Packit |
ea1746 |
};
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
} // namespace internal
|
|
Packit |
ea1746 |
} // namespace ceres
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#endif // CERES_INTERNAL_CANONICAL_VIEWS_CLUSTERING_H_
|