#include <iostream>
#include <vigra/multi_array.hxx>
#include <vigra/multi_resize.hxx>
#include <vigra/colorconversions.hxx>
#include <vigra/multi_convolution.hxx>
#include <vigra/multi_watersheds.hxx>
#include <vigra/multi_gridgraph.hxx>
#include <vigra/accumulator.hxx>
#include <vigra/adjacency_list_graph.hxx>
#include <vigra/graph_algorithms.hxx>
#include <vigra/hierarchical_clustering.hxx>
#include <vigra/metrics.hxx>
int main (int argc, char ** argv)
{
float sigmaGradMag = 3.0f;
float beta = 0.5f;
float wardness = 0.8f;
int numClusters = 30;
if(argc != 3)
{
std::cout << "Usage: " << argv[0] << " infile outfile" << std::endl;
std::cout << "(only color images)" << std::endl;
return 1;
}
try
{
vigra_precondition(info.
numBands() == 3,
"an RGB image is required.");
imageArrayLab(info.
shape());
unsigned int max_label =
ImageGraph imageGraph(labelArray.shape());
RAG rag;
RAG::EdgeMap<std::vector<ImageGraph::Edge>> affiliatedEdges(rag);
RAG::EdgeMap<float> edgeWeights(rag),
edgeLengths(rag);
for(RAG::EdgeIt rag_edge(rag); rag_edge != lemon::INVALID; ++rag_edge)
{
for(unsigned int k = 0; k < affiliatedEdges[*rag_edge].size(); ++k)
{
auto const & grid_edge = affiliatedEdges[*rag_edge][k];
auto start = imageGraph.u(grid_edge),
end = imageGraph.v(grid_edge);
double grid_edge_gradient = 0.5 * (gradMag[start] + gradMag[end]);
edgeWeights[*rag_edge] += grid_edge_gradient;
}
edgeLengths[*rag_edge] = affiliatedEdges[*rag_edge].size();
edgeWeights[*rag_edge] /= edgeLengths[*rag_edge];
}
AccumulatorChainArray<CoupledArrays<2, TinyVector<float, 3>, unsigned int>,
Select<DataArg<1>, LabelArg<2>,
Count, Mean> >
features;
extractFeatures(imageArrayLab, labelArray, features);
RAG::NodeMap<TinyVector<float, 3>> meanColor(rag);
RAG::NodeMap<unsigned int> regionSize(rag);
for(unsigned int k=0; k<=max_label; ++k)
{
meanColor[k] = get<Mean>(features, k);
regionSize[k] = get<Count>(features, k);
}
RAG::NodeMap<unsigned int> nodeLabels(rag);
edgeWeights, edgeLengths, meanColor, regionSize,
nodeLabels,
.nodeFeatureImportance(beta)
.sizeImportance(wardness)
);
[&nodeLabels](unsigned int oldlabel)
{
return nodeLabels[oldlabel];
});
}
catch (std::exception & e)
{
std::cout << e.what() << std::endl;
return 1;
}
return 0;
}
undirected adjacency list graph in the LEMON API
Definition adjacency_list_graph.hxx:228
Options object for hierarchical clustering.
Definition hierarchical_clustering.hxx:647
Define a grid graph in arbitrary dimensions.
Definition multi_gridgraph.hxx:1429
Argument object for the function importImage().
Definition imageinfo.hxx:391
MultiArrayShape< 2 >::type shape() const
Main MultiArray class containing the memory management.
Definition multi_array.hxx:2479
Convert linear (raw) RGB into perceptual uniform CIE L*a*b*.
Definition colorconversions.hxx:1589
Class for a single RGB value.
Definition rgbvalue.hxx:128
Options object for watershed algorithms.
Definition watersheds.hxx:775
void exportImage(...)
Write an image to a file.
void importImage(...)
Read an image from a file.
image import and export functions
Efficient computation of object statistics.
Definition accumulator-grammar.hxx:48
@ L2Norm
Euclidean distance (L2 norm)
Definition metrics.hxx:235
void gaussianGradientMagnitude(...)
Calculate the gradient magnitude by means of a 1st derivatives of Gaussian filter.
void makeRegionAdjacencyGraph(GRAPH_IN graphIn, GRAPH_IN_NODE_LABEL_MAP labels, AdjacencyListGraph &rag, typename AdjacencyListGraph::template EdgeMap< std::vector< typename GRAPH_IN::Edge > > &affiliatedEdges, const Int64 ignoreLabel=-1)
make a region adjacency graph from a graph and labels w.r.t. that graph
Definition graph_algorithms.hxx:165
std::string impexListFormats()
List the image formats VIGRA can read and write.
void regionImageToCrackEdgeImage(...)
Transform a labeled image into a crack edge (interpixel edge) image.
void resizeMultiArraySplineInterpolation(...)
Resize MultiArray using B-spline interpolation.
void hierarchicalClustering(...)
Reduce the number of nodes in a graph by iteratively contracting the cheapest edge.
@ DirectNeighborhood
use only direct neighbors
Definition multi_fwd.hxx:187
void transformMultiArray(...)
Transform a multi-dimensional array with a unary function or functor.
Label watershedsMultiArray(...)
Watershed segmentation of an arbitrary-dimensional array.