### Example Usage with MultiArray and MagnitudeFunctor Source: https://ukoethe.github.io/vigra/doc-release/vigra/group__TransformAlgo This C++ example demonstrates how to use gradientBasedTransform with vigra::MultiArray and a MagnitudeFunctor. It includes the necessary header and shows basic setup for source and destination arrays. ```cpp #include // ... inside a function or scope ... Namespace: vigra MultiArray<2, float> src(w,h), magnitude(w,h); ... gradientBasedTransform(src, magnitude, MagnitudeFunctor()); ``` -------------------------------- ### Vigra AccumulatorChain and Histogram Usage Example (C++) Source: https://ukoethe.github.io/vigra/doc-release/vigra/accumulator_8hxx_source Demonstrates the setup and usage of Vigra's accumulator chain for computing histograms and quantiles. It shows how to define different histogram types, set histogram options globally and per-histogram, and extract the results. This example requires the vigra library and assumes a MultiArray named 'data' is defined. ```cpp using namespace vigra::acc; typedef double DataType; vigra::MultiArray<2, DataType> data(...); typedef UserRangeHistogram<40> SomeHistogram; //binCount set at compile time typedef UserRangeHistogram<0> SomeHistogram2; // binCount must be set at run-time typedef AutoRangeHistogram<0> SomeHistogram3; typedef StandardQuantiles Quantiles3; AccumulatorChain > a; //set options for all histograms in the accumulator chain: vigra::HistogramOptions histogram_opt; histogram_opt = histogram_opt.setBinCount(50); //histogram_opt = histogram_opt.setMinMax(0.1, 0.9); // this would set min/max for all three histograms, but range bounds // shall be set automatically by min/max of data for SomeHistogram3 a.setHistogramOptions(histogram_opt); // set options for a specific histogram in the accumulator chain: getAccumulator(a).setMinMax(0.1, 0.9); // number of bins must be set before setting min/max getAccumulator(a).setMinMax(0.0, 1.0); extractFeatures(data.begin(), data.end(), a); vigra::TinyVector hist = get(a); vigra::MultiArray<1, double> hist2 = get(a); vigra::TinyVector quant = get(a); double right_outliers = getAccumulator(a).right_outliers; ``` -------------------------------- ### MultiImageAccessor2 Usage Example Source: https://ukoethe.github.io/vigra/doc-release/vigra/accessor_8hxx_source Provides a basic usage example for MultiImageAccessor2, demonstrating its inclusion and namespace usage in C++. ```cpp using namespace vigra; ``` -------------------------------- ### Complex Fourier Transform (Old-style 2D Example) Source: https://ukoethe.github.io/vigra/doc-release/vigra/group__FourierTransform Example demonstrating the old-style complex Fourier transform of a real image using `vigra::FFTWComplexImage`. Requires ``. ```cpp // compute complex Fourier transform of a real image, old-style implementation vigra::DImage src(w, h); vigra::FFTWComplexImage fourier(w, h); fourierTransform(srcImageRange(src), destImage(fourier)); ``` -------------------------------- ### Usage Example: differenceOfExponentialCrackEdgeImage Source: https://ukoethe.github.io/vigra/doc-release/vigra/group__EdgeDetection An example demonstrating the usage of `differenceOfExponentialCrackEdgeImage` with `vigra::BImage`. It initializes source and destination images, then calls the function to find edges with specified parameters. ```cpp #include // Assuming w and h are defined for image dimensions vigra::BImage src(w,h), edges(2*w-1,2*h-1); // empty edge image edges = 0; // find edges at scale 0.8 with gradient larger than 4.0, mark with 1 vigra::differenceOfExponentialCrackEdgeImage(srcImageRange(src), destImage(edges), 0.8, 4.0, 1); ``` -------------------------------- ### resamplingConvolveY: Usage Example with Image Iterators Source: https://ukoethe.github.io/vigra/doc-release/vigra/group__ResamplingConvolutionFilters Demonstrates using `resamplingConvolveY` with image iterators for enlarging and smoothing an image. This example uses `srcImageRange` and `destImageRange` for convenient iterator access. ```cpp #include ... Rational ratio(2), offset(0); FImage src(w,h), dest(w, rational_cast(ratio*h)); float sigma = 2.0; Gaussian smooth(sigma); // simultaneously enlarge and smooth source image resamplingConvolveY(srcImageRange(src), destImageRange(dest), smooth, ratio, offset); ``` -------------------------------- ### resampleImage: Usage Example C++ Source: https://ukoethe.github.io/vigra/doc-release/vigra/basicgeometry_8hxx_source Example demonstrating the usage of vigra::resampleImage to enlarge an image by a specified factor. Requires \#include . ```cpp double factor = 2.0; MultiArray<2, float> src(width, height), dest((int)(factor*width), (int)(factor*height)); // enlarge image by factor ... // fill src resampleImage(src, dest, factor); ``` -------------------------------- ### Distance Transform Usage Example (C++) Source: https://ukoethe.github.io/vigra/doc-release/vigra/group__DistanceTransform Example demonstrating the usage of vigra::distanceTransform with MultiArray. It first detects edges and then computes the Euclidean distance transform. Requires vigra/distancetransform.hxx and vigra/differenceofexponential.hxx. ```cpp #include #include // ... assuming src, edges, distance are MultiArray<2, ...> objects // detect edges in src image (edges will be marked 1, background 0) differenceOfExponentialEdgeImage(src, edges, 0.8, 4.0); // find distance of all pixels from nearest edge distanceTransform(edges, distance, 0, 2); // ^ background label ^ norm (Euclidean) ``` -------------------------------- ### Real-to-Complex Fourier Transform (New-style N-D Example) Source: https://ukoethe.github.io/vigra/doc-release/vigra/group__FourierTransform Example of computing a Fourier transform from a real 2D `MultiArray` to a complex 2D `MultiArray` using the R2C algorithm. Requires ``. ```cpp // compute Fourier transform of a real array, using the R2C algorithm MultiArray<2, double> src(Shape2(w, h)); MultiArray<2, FFTWComplex > fourier(fftwCorrespondingShapeR2C(src.shape())); fourierTransform(src, fourier); ``` -------------------------------- ### resamplingConvolveY: Usage Example with MultiArray Source: https://ukoethe.github.io/vigra/doc-release/vigra/group__ResamplingConvolutionFilters Example demonstrating the usage of `resamplingConvolveY` to simultaneously enlarge and smooth a source image represented by a `vigra::MultiArray`. It utilizes `vigra::Gaussian` as the smoothing kernel. ```cpp #include ... Rational ratio(2), offset(0); MultiArray<2, float> src(w,h), dest(w, rational_cast(ratio*h)); float sigma = 2.0; Gaussian smooth(sigma); // simultaneously enlarge and smooth source image resamplingConvolveY(src, dest, smooth, ratio, offset); ``` -------------------------------- ### Example Usage of LocalMinmaxOptions Source: https://ukoethe.github.io/vigra/doc-release/vigra/localminmax_8hxx_source Demonstrates how to instantiate and configure `LocalMinmaxOptions` for detecting local minima. This example shows setting the neighborhood to 4, allowing detection at the image border, and applying a threshold. ```cpp MultiArray<2, unsigned char> src(w,h), minima(w,h); // ... fill src localMinima(src, minima, LocalMinmaxOptions().neighborhood(4).allowAtBorder().threshold(5)); ``` -------------------------------- ### Inverse Complex Fourier Transform (Old-style 2D Example) Source: https://ukoethe.github.io/vigra/doc-release/vigra/group__FourierTransform Example demonstrating the old-style inverse complex Fourier transform using `vigra::FFTWComplexImage`. Both source and destination must be `FFTWComplexImage`. Requires ``. ```cpp // compute inverse Fourier transform // note that both source and destination image must be of type vigra::FFTWComplexImage vigra::FFTWComplexImage inverseFourier(w, h); fourierTransformInverse(srcImageRange(fourier), destImage(inverseFourier)); ``` -------------------------------- ### Box Utility: Get Start Point - vigra::Box::begin Source: https://ukoethe.github.io/vigra/doc-release/vigra/multi__blocking_8hxx_source Returns a constant reference to the starting Vector (corner) of the Box. This defines one of the boundaries of the box. ```c++ Vector const & begin() const // Returns the beginning corner of the box ``` -------------------------------- ### Get Start Node of Edge (LEMON) Source: https://ukoethe.github.io/vigra/doc-release/vigra/multi__gridgraph_8hxx_source Retrieves the start node ('u') of a given edge. This function is specific to the LEMON API and is analogous to `boost::source(e, graph)`. ```C++ Node u(Edge const & e) const { return Node(e.template subarray<0,N>()); } ``` -------------------------------- ### Example Usage of unionFindWatershedsBlockwise Source: https://ukoethe.github.io/vigra/doc-release/vigra/blockwise__watersheds_8hxx_source This code demonstrates how to use the `unionFindWatershedsBlockwise` function with `ChunkedArrayLazy` objects. It includes setup for data and labels, followed by a call to the function. This example assumes data has been filled. ```c++ #include using namespace vigra; Shape3 shape = Shape3(10); Shape3 chunk_shape = Shape3(4); ChunkedArrayLazy<3, int> data(shape, chunk_shape); // fill data ... ChunkedArrayLazy<3, size_t> labels(shape, chunk_shape); unionFindWatershedsBlockwise(data, labels, IndirectNeighborhood); ``` -------------------------------- ### HDF5File Constructors in C++ Source: https://ukoethe.github.io/vigra/doc-release/vigra/classvigra_1_1HDF5File Provides examples of various HDF5File constructors in C++. These constructors allow for default initialization, enabling time tagging of datasets, opening or creating files with specified paths and modes, and initializing from existing HDF5 file handles or by copying other HDF5File objects. ```C++ // Default constructor HDF5File file_default; // file_default.open("path/to/file", HDF5File::ReadOnly); // Constructor with time tracking enabled HDF5File file_time_tracking(true); // Constructor to open or create a file (string path) HDF5File file_string("my_data.h5", HDF5File::ReadWrite); // Constructor to open or create a file (char const* path) HDF5File file_char("my_data.h5", HDF5File::ReadWrite); // Constructor from an existing file handle (ownership shared) // Assume hdf5_handle is a valid HDF5HandleShared object // HDF5File file_from_handle(hdf5_handle, "/group", false); // Copy constructor // HDF5File file_copy(file_string); ``` -------------------------------- ### Watershed Example 3: Biased Watershed (C++) Source: https://ukoethe.github.io/vigra/doc-release/vigra/group__Superpixels This C++ example illustrates how to bias the watershed algorithm to prefer a specific label (e.g., background label 1) by reducing its cost. This can be useful for guiding the segmentation process. ```cpp #include #include // ... assuming gradMag, labeling, w, h are defined MultiArray<2, unsigned int> labeling(w, h); // bias the watershed algorithm so that the background is preferred // by reducing the cost for label 1 to 90% watershedsRegionGrowing(gradMag, labeling, WatershedOptions().biasLabel(1, 0.9)); ``` -------------------------------- ### Box Accessors Source: https://ukoethe.github.io/vigra/doc-release/vigra/box_8hxx_source Provides methods to get the start and end vectors of the box, as well as its volume and size. ```APIDOC ## GET /box/end ### Description Returns the end vector of the box. This represents the coordinates higher than the begin vector in each dimension. For floating-point types, it's the first point outside the box; for integers, it's the last point within the box. ### Method GET ### Endpoint `/box/end` ### Parameters None ### Response #### Success Response (200) - **Vector** (Vector) - The end vector of the box. #### Response Example ```json { "end_vector": [10.0, 20.0] } ``` ## GET /box/volume ### Description Calculates and returns the volume of the box. If the box is empty, it returns zero. Otherwise, it returns the product of the extents in each dimension. ### Method GET ### Endpoint `/box/volume` ### Parameters None ### Response #### Success Response (200) - **VolumeType** (number) - The volume of the box. #### Response Example ```json { "volume": 200.0 } ``` ## GET /box/size ### Description Determines and returns the size (extent) of the box in each dimension. The size might be zero or negative in some dimensions, which would indicate an empty box. ### Method GET ### Endpoint `/box/size` ### Parameters None ### Response #### Success Response (200) - **Vector** (Vector) - The size vector of the box. #### Response Example ```json { "size_vector": [10.0, 10.0] } ``` ``` -------------------------------- ### Usage Example: Standardizing Matrix Data (C++) Source: https://ukoethe.github.io/vigra/doc-release/vigra/matrix_8hxx_source This example demonstrates how to use the `prepareColumns` function to standardize a matrix `A`. It shows how to pass the matrix, output matrices for the standardized data, offset, and scaling, and specify the desired preparation goals. It also illustrates how to use the computed offset and scaling to standardize new data consistently. ```cpp Matrix A(rows, columns); .. // fill A Matrix standardizedA(rows, columns), offset(1, columns), scaling(1, columns); prepareColumns(A, standardizedA, offset, scaling, ZeroMean | UnitNorm); // use offset and scaling to prepare additional data according to the same transformation Matrix newData(nrows, columns); Matrix standardizedNewData = (newData - repeatMatrix(offset, nrows, 1)) * pointWise(repeatMatrix(scaling, nrows, 1)); ``` -------------------------------- ### Get Axis Permutation for Setup Order (C++) Source: https://ukoethe.github.io/vigra/doc-release/vigra/numpy__array__traits_8hxx_source Retrieves the axis permutation required to transform an array into a specific 'setup order'. This is useful for consistent data handling across different array orientations. It handles cases with or without explicit channel axes. ```cpp template static void permutationToSetupOrder(python_ptr array, ArrayVector & permute) { detail::getAxisPermutationImpl(permute, array, "permutationToNormalOrder", AxisInfo::AllAxes, true); if(permute.size() == 0) { permute.resize(N); linearSequence(permute.begin(), permute.end()); } else if(permute.size() == N+1) { permute.erase(permute.begin()); } } ``` -------------------------------- ### Example Usage of prepareRows (C++) Source: https://ukoethe.github.io/vigra/doc-release/vigra/matrix_8hxx_source Demonstrates how to use the prepareRows function to standardize a matrix and then use the computed offset and scaling to standardize new data. ```cpp Matrix A(rows, columns); .. // fill A Matrix standardizedA(rows, columns), offset(rows, 1), scaling(rows, 1); prepareRows(A, standardizedA, offset, scaling, ZeroMean | UnitNorm); // use offset and scaling to prepare additional data according to the same transformation Matrix newData(rows, ncolumns); Matrix standardizedNewData = (newData - repeatMatrix(offset, 1, ncolumns)) * pointWise(repeatMatrix(scaling, 1, ncolumns)); ``` -------------------------------- ### Cross-correlation example usage in C++ Source: https://ukoethe.github.io/vigra/doc-release/vigra/correlation_8hxx_source This C++ code snippet demonstrates the usage of the `crossCorrelation` function. It initializes `MultiArray` objects for the mask, source image, and destination array, and then calls `crossCorrelation` to compute the correlation. The example assumes appropriate includes and setup for Vigra. ```cpp #include // ... other necessary includes and setup ... unsigned int m_w=51, m_h=51; unsigned int w=1000, h=1000; MultiArray<2, float> mask(m_w,m_h), src(w,h), dest(w,h); // ... fill mask and src with data ... //compute (slow) cross correlation of mask and image -> dest // vigra::crossCorrelation(src, mask, dest); // Example using the MultiArrayView overload ``` -------------------------------- ### vigra::rf::algorithms::ClusterImportanceVisitor::visit_at_beginning Source: https://ukoethe.github.io/vigra/doc-release/vigra/rf__algorithm_8hxx_source A method within ClusterImportanceVisitor that is executed at the start of a traversal or learning process. It may be used for initialization or setup. ```cpp void visit_at_beginning(RF const &rf, PR const &) ``` -------------------------------- ### Get Source Vertex of an Edge in GridGraph Source: https://ukoethe.github.io/vigra/doc-release/vigra/multi__gridgraph_8hxx_source Returns the vertex descriptor for the starting vertex of a given edge in a VIGRA GridGraph. This function is part of the boost API. ```C++ template inline typename vigra::GridGraph::vertex_descriptor source(typename vigra::GridGraph::edge_descriptor const & e, vigra::GridGraph const & g) { return g.source(e); } ``` -------------------------------- ### BasicImage Initialization and Resizing Source: https://ukoethe.github.io/vigra/doc-release/vigra/classvigra_1_1BasicImage Initializes the image with a constant pixel value. Provides multiple resize functions: to a specified size, to a specified size with initialization data, to skip initialization for certain types, and copying data from a C-style array or another BasicImage. ```C++ BasicImage< PIXELTYPE, Alloc > & init( value_type const & _pixel_ ); void resize( std::ptrdiff_t _width, std::ptrdiff_t _height ); void resize( difference_type const & _size ); void resize( std::ptrdiff_t _width, std::ptrdiff_t _height, value_type const & _d ); void resize( std::ptrdiff_t _width, std::ptrdiff_t _height, SkipInitializationTag ); void resizeCopy( std::ptrdiff_t _width, std::ptrdiff_t _height, const_pointer _data_ ); void resizeCopy( const BasicImage< PIXELTYPE, Alloc > & _rhs_ ); ``` -------------------------------- ### BasicImage Initialization and Resizing Source: https://ukoethe.github.io/vigra/doc-release/vigra/classvigra_1_1BasicImage Functions for initializing and resizing the image, with various options for content initialization. ```APIDOC ## Initialization and Resizing ### Description Functions to initialize the image with a constant value and to resize the image to new dimensions, with options for initializing new pixels. ### Methods * **`init`**: Sets all pixels to a constant value. * **`resize`**: Resizes the image to specified width and height. Old data is kept if the new size matches the old size. * **`resize`**: Resizes the image and initializes new pixels with a given value. * **`resize`**: Resizes the image and skips initialization if possible (e.g., for built-in types). * **`resizeCopy`**: Resizes the image and initializes by copying data from a C-style array. * **`resizeCopy`**: Resizes the image to the size of another image and copies its data. ### Parameters * **`_pixel`**: The value to initialize pixels with. * **`_width`**: The new width of the image. * **`_height`**: The new height of the image. * **`_d`**: The value to initialize new pixels with. * **`SkipInitializationTag`**: Tag to skip initialization. * **`_data`**: Pointer to the C-style array containing data to copy. * **`_rhs`**: Another BasicImage to copy dimensions and data from. ### Request Example ```cpp BasicImage img; img.init(0); // Initialize all pixels to 0 img.resize(100, 200); float data[] = {1.0f, 2.0f, 3.0f}; img.resizeCopy(1, 3, data); BasicImage other_img; img.resizeCopy(other_img); ``` ### Response * **`BasicImage &`**: Returns a reference to the modified image for chaining. * **`void`**: For `resizeCopy` methods. ``` -------------------------------- ### Get Base Node from Iterator (LEMON API) Source: https://ukoethe.github.io/vigra/doc-release/vigra/adjacency__list__graph_8hxx_source Retrieves the base (start) node associated with an edge or arc iterator. This function is part of the LEMON API. ```cpp Node baseNode(const IncEdgeIt & iter)const; Node baseNode(const OutArcIt & iter)const; ``` -------------------------------- ### resamplingConvolveImage: Usage Example Source: https://ukoethe.github.io/vigra/doc-release/vigra/group__ResamplingConvolutionFilters Example demonstrating `resamplingConvolveImage` to enlarge and smooth a source image using different `vigra::Gaussian` kernels for x and y directions. It showcases the use of `vigra::Rational` for sampling ratios and offsets. ```cpp #include ... Rational xratio(2), yratio(3), offset(0); MultiArray<2, float> src(w,h), dest(rational_cast(xratio*w), rational_cast(yratio*h)); float sigma = 2.0; Gaussian smooth(sigma); // simultaneously enlarge and smooth source image resamplingConvolveImage(src, dest, smooth, xratio, offset, smooth, yratio, offset); ``` -------------------------------- ### TinyVectorBase Initialization Source: https://ukoethe.github.io/vigra/doc-release/vigra/multi__array_8hxx_source Details on initializing TinyVectorBase objects. ```APIDOC ## TinyVectorBase Initialization ### Description Covers the initialization of TinyVectorBase objects. ### init #### Method `void init(Iterator i, Iterator end)` #### Description Initializes the TinyVectorBase using a range specified by iterators. ``` -------------------------------- ### Get Arc Source and Target Nodes (LEMON API) Source: https://ukoethe.github.io/vigra/doc-release/vigra/adjacency__list__graph_8hxx_source Retrieves the source (start) and target (end) nodes of a given arc. This function is part of the LEMON API. ```cpp Node source(const Arc & arc)const; Node target(const Arc & arc)const; ``` -------------------------------- ### Get Total Count for a Node (C++) Source: https://ukoethe.github.io/vigra/doc-release/vigra/random__forest__deprec_8hxx_source Returns the total count of examples for a specific class within a decision tree node. This function retrieves a pre-calculated value, likely from the 'bestTotalCounts' member. ```cpp unsigned int totalCount(int k) const { return (unsigned int)bestTotalCounts[k]; } ``` -------------------------------- ### AccumulatorChain Template Usage Example Source: https://ukoethe.github.io/vigra/doc-release/vigra/accumulator_8hxx_source This example demonstrates how to instantiate AccumulatorChain with different input types (DataType and Handle) and various statistics (Variance, Mean, Minimum, DataArg, WeightArg). It illustrates the flexibility of AccumulatorChain in selecting and configuring statistics for different data processing needs. ```cpp typedef double DataType; AccumulatorChain > accumulator; const int dim = 3; //dimension of MultiArray typedef double DataType; typedef double WeightType; typedef vigra::CoupledIteratorType::HandleType Handle; AccumulatorChain, WeightArg<2>, Mean,...> > a; ``` -------------------------------- ### Get Base Node from Incident Edge Iterator - C++ Source: https://ukoethe.github.io/vigra/doc-release/vigra/multi__gridgraph_8hxx_source Retrieves the starting node of the edge pointed to by an incident edge iterator. This function is fundamental for traversing the graph and accessing nodes connected by edges. ```cpp Node baseNode(IncEdgeIt const & e) const ``` -------------------------------- ### Watershed Example 1 with Image Range (C++) Source: https://ukoethe.github.io/vigra/doc-release/vigra/group__Superpixels This C++ example demonstrates watershed computation using vigra::BImage and Image Range accessors. It computes seeds from gradient minima and applies the watershed algorithm with contour keeping. ```cpp #include #include #include // ... assuming w, h are defined vigra::BImage src(w, h); // ... read input data // compute gradient magnitude at scale 1.0 as a boundary indicator vigra::FImage gradMag(w, h); gaussianGradientMagnitude(srcImageRange(src), destImage(gradMag), 1.0); // the pixel type of the destination image must be large enough to hold // numbers up to 'max_region_label' to prevent overflow vigra::IImage labeling(w, h); // call watershed algorithm for 4-neighborhood, leave a 1-pixel boundary between regions, // and autogenerate seeds from all gradient minima where the magnitude is below 2.0 unsigned int max_region_label = watershedsRegionGrowing(srcImageRange(gradMag), destImage(labeling), FourNeighborCode(), WatershedOptions().keepContours() .seedOptions(SeedOptions().minima().threshold(2.0))); ``` -------------------------------- ### Get Source Node of an Edge (C++) Source: https://ukoethe.github.io/vigra/doc-release/vigra/graph__algorithms_8hxx_source Retrieves the source node of a given edge in a graph. This function is part of the ShortestPathDijkstra algorithm's API and is used to determine the starting node of an edge. ```cpp const Node & source() const get the source node ``` -------------------------------- ### C++: Usage example for labelVolume functions Source: https://ukoethe.github.io/vigra/doc-release/vigra/labelvolume_8hxx_source Demonstrates the usage of vigra's labelVolume and labelVolumeSix functions for calculating region labels in a 3D image. It shows how to initialize MultiArray objects for source and destination and call the respective functions for 6-connected and 26-connected regions. ```cpp typedef MultiArray<3,int> IntVolume; IntVolume src(Shape3(w,h,d)); IntVolume dest(Shape3(w,h,d)); // find 6-connected regions int max_region_label = labelVolumeSix(src, dest); // find 26-connected regions int max_region_label = labelVolume(src, dest, NeighborCode3DTwentySix()); ``` -------------------------------- ### Get Coefficient Array Source: https://ukoethe.github.io/vigra/doc-release/vigra/classvigra_1_1SplineImageView Retrieves the polynomial coefficients for the facet containing the point (x, y). The output array 'res' must have dimensions (ORDER+1)x(ORDER+1). The example demonstrates how to use these coefficients to calculate the interpolated function value. ```C++ void coefficientArray(double _x, double _y, Array & _res) const; // Example usage: SplineImageView view(...); double x = ..., y = ...; BasicImage coefficients; view.coefficientArray(x, y, coefficients); float f_x_y = 0.0; for(int ny = 0; ny < ORDER + 1; ++ny) for(int nx = 0; nx < ORDER + 1; ++nx) f_x_y += pow(dx, nx) * pow(dy, ny) * coefficients(nx, ny); assert(abs(f_x_y - view(x, y)) < 1e-6); ``` -------------------------------- ### Watershed Segmentation with Pre-generated Seeds and 8-Neighborhood (C++) Source: https://ukoethe.github.io/vigra/doc-release/vigra/group__Superpixels This example shows how to pre-generate seeds based on a threshold in the gradient magnitude image and then perform watershed segmentation using an 8-neighborhood. It also includes an optimization for 8-bit data by quantizing the gradient magnitude. ```c++ #include #include #include #include #include #include #include // Assuming src, w, h are defined and input data is read into src // For demonstration, let's define them: const int w = 100; const int h = 100; vigra::MultiArray<2, unsigned char> src(vigra::Shape2(w, h)); // ... read input data into src ... // compute gradient magnitude at scale 1.0 as a boundary indicator vigra::MultiArray<2, float> gradMag(src.shape()); vigra::gaussianGradientMagnitude(vigra::srcImageRange(src), vigra::destImage(gradMag), 1.0); // example 2 { vigra::MultiArray<2, unsigned int> labeling(src.shape()); // compute seeds beforehand (use connected components of all pixels // where the gradient is below 4.0) unsigned int max_region_label = vigra::generateWatershedSeeds(gradMag, labeling, vigra::SeedOptions().levelSets(4.0)); // quantize the gradient image to 256 gray levels float m, M; gradMag.minmax(&m, &M); using namespace vigra::multi_math; vigra::MultiArray<2, unsigned char> gradMag256(255.0 / (M - m) * (gradMag - m)); // call region-growing algorithm with 8-neighborhood, // since the data are 8-bit, a faster priority queue will be used vigra::watershedsMultiArray(gradMag256, labeling, vigra::IndirectNeighborhood); } ``` -------------------------------- ### Usage Example: Local Minima in 3D Array (C++) Source: https://ukoethe.github.io/vigra/doc-release/vigra/group__LocalMinMax Example demonstrating the usage of vigra::localMinima for a 3D multi-array. Shows default parameterization and custom options like direct neighborhood and allowing minima at the border. ```C++ // 3D examples (other dimensions work likewise) Shape3 shape(w,h,d); MultiArray<3, unsigned char> src(shape), minima(shape); ... // fill src // use default parameterisation localMinima(src, minima); // reset destination image minima = 0; // use direct neighborhood (i.e. 6-neighborhood since we are in 3D) // and allow minima at the image border localMinima(src, minima, LocalMinmaxOptions().neighborhood(0).allowAtBorder()); ``` -------------------------------- ### Get Source Vertex Descriptor (C++) Source: https://ukoethe.github.io/vigra/doc-release/vigra/blockwise__convolution_8hxx_source Retrieves the vertex descriptor for the starting vertex of a given edge in a directed grid graph. This function is part of the boost graph API integration within Vigra. ```cpp vigra::GridGraph< N, DirectedTag >::vertex_descriptor source(typename vigra::GridGraph< N, DirectedTag >::edge_descriptor const &e, vigra::GridGraph< N, DirectedTag > const &g) ``` -------------------------------- ### VIGRA MultiArrayNavigator Usage Example (C++) Source: https://ukoethe.github.io/vigra/doc-release/vigra/classvigra_1_1MultiArrayNavigator Demonstrates how to use the MultiArrayNavigator to iterate over 1D subranges of a 3D array. It shows the setup for the navigator and nested loops for accessing subranges along different dimensions. ```cpp #include // Assuming VIGRA is installed and accessible // Example usage within a C++ program: // Define a 3D array type // typedef vigra::MultiArray<3, int> Array; // // Create a 3D array // Array a(Array::size_type(X, Y, Z)); // Define the Navigator type for a 3D array // typedef vigra::MultiArrayNavigator Navigator; // for(int d=0; d<3; ++d) // { // // create Navigator for dimension d // Navigator nav(a.traverser_begin(), a.shape(), d); // // outer loop: move navigator to all starting points // // of 1D subsets that run parallel to coordinate axis d // for(; nav.hasMore(); ++nav) // { // // inner loop: linear iteration over current subset // // d == {0, 1, 2}: iterate along {x, y, z}-axis respectively // Navigator::iterator i = nav.begin(), end = nav.end(); // for(; i != end; ++i) // // do something with the element pointed to by i // } // } ``` -------------------------------- ### Watershed Example 2: Precomputed Seeds and Turbo Algorithm (C++) Source: https://ukoethe.github.io/vigra/doc-release/vigra/group__Superpixels This C++ example shows how to compute watershed regions using precomputed seeds derived from gradient level sets. It also demonstrates quantizing the gradient image and applying the turbo watershed algorithm for faster computation. ```cpp #include #include #include #include // ... assuming w, h are defined MultiArray<2, unsigned int> labeling(w, h); // compute seeds beforehand (use connected components of all pixels // where the gradient is below 4.0) unsigned int max_region_label = generateWatershedSeeds(gradMag, labeling, SeedOptions().levelSets(4.0)); // quantize the gradient image to 256 gray levels MultiArray<2, unsigned char> gradMag256(w, h); vigra::FindMinMax minmax; inspectImage(gradMag, minmax); // find original range transformImage(gradMag, gradMag256, linearRangeMapping(minmax, 0, 255)); // call the turbo algorithm with 256 bins, using 8-neighborhood watershedsRegionGrowing(gradMag256, labeling, WatershedOptions().turboAlgorithm(256)); ``` -------------------------------- ### Find Local Maxima in 3D MultiArray (C++ Example) Source: https://ukoethe.github.io/vigra/doc-release/vigra/group__LocalMinMax Example demonstrating the usage of localMaxima for a 3D MultiArray. It shows how to initialize arrays, fill the source array, and call localMaxima with default and custom options. Requires vigra/localminmax.hxx and vigra/multi_localminmax.hxx. ```cpp // 3D examples (other dimensions work likewise) Shape3 shape(w,h,d); MultiArray<3, unsigned char> src(shape), maxima(shape); ... // fill src // use default parameterisation localMaxima(src, maxima); // reset destination image maxima = 0; // use direct neighborhood (i.e. 6-neighborhood sine we are in 3D) // and allow maxima at the image border localMaxima(src, maxima, LocalMinmaxOptions().neighborhood(0).allowAtBorder()); ``` -------------------------------- ### C++ MultiArrayNavigator (1D specialization) Range Access Source: https://ukoethe.github.io/vigra/doc-release/vigra/navigator_8hxx_source Provides `begin()` and `end()` methods to get iterators for the 1D sub-range. `begin()` returns an iterator to the start of the current sub-range, and `end()` returns an iterator to the position after the last element of the sub-range. ```cpp iterator begin() const { return i_.iteratorForDimension(inner_dimension_); } iterator end() const { return begin() + inner_shape_; } ``` -------------------------------- ### Get Graph Source Vertex from Edge (C++) Source: https://ukoethe.github.io/vigra/doc-release/vigra/labelvolume_8hxx_source Retrieves a vertex descriptor for the start vertex of a given edge within a graph. This function is part of the boost graph integration within Vigra, providing access to graph traversal information. ```cpp #include // ... (other includes and setup) // Assuming g is a vigra::GridGraph and e is an edge descriptor vigra::GridGraph::vertex_descriptor startVertex; startVertex = vigra::source(e, g); ``` -------------------------------- ### EarlyStoppStd Constructor Source: https://ukoethe.github.io/vigra/doc-release/vigra/rf__common_8hxx_source Initializes EarlyStoppStd with a minimum split node size from an options object. ```C++ template EarlyStoppStd(Opt opt) : min_split_node_size_(opt.min_split_node_size_) {} ``` -------------------------------- ### Get Source Vertex Descriptor C++ Source: https://ukoethe.github.io/vigra/doc-release/vigra/impexbase_8hxx_source Retrieves the vertex descriptor for the starting vertex of a given edge in a vigra GridGraph. This function is part of the vigra library's graph utilities and adheres to the Boost Graph Library API for graph traversal. ```cpp vigra::boost_graph::source vigra::GridGraph< N, DirectedTag >::vertex_descriptor source(typename vigra::GridGraph< N, DirectedTag >::edge_descriptor const &e, vigra::GridGraph< N, DirectedTag > const &g) { // Get a vertex descriptor for the start vertex of edge e in graph g (API: boost). } ``` -------------------------------- ### Obtaining a 1D Iterator for a Specific Dimension Source: https://ukoethe.github.io/vigra/doc-release/vigra/multi__iterator_8hxx_source This snippet shows how to get a 1D, STL-compatible iterator for a given dimension 'd' from a StridedMultiIterator. This allows for iterating along a specific column or row within the multi-dimensional array, starting from the iterator's current position. ```cpp StridedMultiIterator<3, int> outer = ...; // this iterator StridedMultiIterator<3, int>::iterator i = outer.iteratorForDimension(1); StridedMultiIterator<3, int>::iterator end = i + height; for(; i != end; ++i) { // go down the current column starting at the location of 'outer' } ``` -------------------------------- ### Initialize Matrices: identityMatrix and ones Source: https://ukoethe.github.io/vigra/doc-release/vigra/group__LinearAlgebraFunctions These functions initialize matrices. `identityMatrix` can initialize an existing matrix view as an identity matrix or create a new identity matrix of a specified size. `ones` creates a matrix filled with ones. Include or . ```cpp #include // or #include // Example usage: // vigra::identityMatrix(mySquareMatrixView); // vigra::Matrix idMat = vigra::identityMatrix(size); // vigra::Matrix onesMat = vigra::ones(rows, cols); ``` -------------------------------- ### Get Edge Source and Target Nodes (LEMON API) Source: https://ukoethe.github.io/vigra/doc-release/vigra/adjacency__list__graph_8hxx_source Retrieves the source (start) and target (end) nodes of a given edge. The LEMON API is used, with a note that boost::graph provides similar functionality via free functions. ```cpp Node u(const Edge & edge)const; Node v(const Edge & edge)const; ``` -------------------------------- ### C++: DynamicAccumulatorChainArray Usage Example Source: https://ukoethe.github.io/vigra/doc-release/vigra/classvigra_1_1acc_1_1DynamicAccumulatorChainArray Example demonstrating the usage of DynamicAccumulatorChainArray with specified data types, weights, labels, and selected statistics. This illustrates how to initialize and potentially use the accumulator chain. ```cpp #include #include // ... (other includes and definitions) const int dim = 3; //dimension of MultiArray typedef double DataType; typedef double WeightType; typedef unsigned int LabelType; typedef vigra::CoupledIteratorType::HandleType Handle; // Example instantiation with selected statistics (Mean, Variance, etc.) vigra::acc::DynamicAccumulatorChainArray, vigra::WeightArg<2>, vigra::LabelArg<3>, vigra::Mean, vigra::Variance>> a; // Further usage would involve iterating and updating the accumulator chain. // For example: // for (Handle h : iterator) { // a.updatePassN(h, 1.0, 0); // Assuming one pass for simplicity // } ``` -------------------------------- ### vigra::localMaxima Usage with MultiArray Source: https://ukoethe.github.io/vigra/doc-release/vigra/localminmax_8hxx_source Example demonstrating the usage of vigra::localMaxima with vigra::MultiArray for 3D images. It shows how to use default parameters and how to specify neighborhood and border options. ```cpp // 3D examples (other dimensions work likewise) Shape3 shape(w,h,d); MultiArray<3, unsigned char> src(shape), maxima(shape); ... // fill src // use default parameterisation localMaxima(src, maxima); // reset destination image maxima = 0; // use direct neighborhood (i.e. 6-neighborhood sine we are in 3D) // and allow maxima at the image border localMaxima(src, maxima, LocalMinmaxOptions().neighborhood(0).allowAtBorder()); ``` -------------------------------- ### Get Chunk Begin Iterator (Mutable) (C++) Source: https://ukoethe.github.io/vigra/doc-release/vigra/multi__array__chunked_8hxx_source This C++ function returns a mutable chunk iterator for a specified sub-range of the MultiArrayView. It first validates the provided 'start' and 'stop' bounds using 'checkSubarrayBounds' and then constructs a 'chunk_iterator' object initialized with the MultiArrayView, range, chunk start/stop positions, and chunk shape. ```cpp chunk_iterator chunk_begin(shape_type const & start, shape_type const & stop) { checkSubarrayBounds(start, stop, "MultiArrayView::chunk_begin()") return chunk_iterator(this, start, stop, chunkStart(start), chunkStop(stop), this->chunk_shape_); } ``` -------------------------------- ### Complex Fourier Transform (New-style Standard N-D Example) Source: https://ukoethe.github.io/vigra/doc-release/vigra/group__FourierTransform Example of computing a Fourier transform from a real 2D `MultiArray` to a complex 2D `MultiArray` using the standard algorithm. Requires ``. ```cpp // compute Fourier transform of a real array with standard algorithm MultiArray<2, double> src(Shape2(w, h)); MultiArray<2, FFTWComplex > fourier(src.shape()); fourierTransform(src, fourier); ``` -------------------------------- ### Get Dataset Shape Source: https://ukoethe.github.io/vigra/doc-release/vigra/classvigra_1_1HDF5File Retrieves the shape of each dimension for a specified dataset. It handles both absolute and relative paths, interpreting paths starting with '/' as absolute. Note that the returned shape order is reversed compared to the file's memory order (Vigra's Fortran-order vs. HDF5's C-order). ```C++ ArrayVector getDatasetShape( std::string _datasetName_ ) const ``` -------------------------------- ### VIGRA Image Processing Calling Conventions Source: https://ukoethe.github.io/vigra/doc-release/vigra/ImageProcessingTutorial Demonstrates VIGRA's uniform calling convention for image processing functions, which start with input and output arrays followed by parameters. It also shows examples of using MultiArrayView for different dimensionalities and mentions deprecated iterator-based APIs. ```c++ // determine the connected components in a binary image, using the 8-neighborhood MultiArray<2, UInt8> image(width, height); MultiArray<2, UInt32> labels(width, height); ... // fill image labelImage(image, labels, true); // smooth a 3D array with a gaussian filter with sigma=2.0 MultiArray<3, float> volume(Shape3(300, 200, 100)), smoothed(Shape3(300, 200, 100)); ... // fill volume gaussianSmoothMultiArray(volume, smoothed, 2.0); // compute the determinant of a 5x5 matrix MultiArray<2, float> matrix(Shape2(5, 5)); ... // fill matrix with data float det = linalg::determinant(matrix); // compute the pixel-wise square root of an image (deprecated API) MultiArray<2, float> input(Shape2(200, 100)), result(imput.shape()); ... // fill input with data transformImage(srcImageRange(input), destImage(result), &sqrt); // deprecated API // compute the element-wise square root of a 4-dimensional array (deprecated API) MultiArray<4, float> input(Shape4(200, 100, 50, 30)), result(imput.shape()); ... // fill input with data transformMultiArray(srcMultiArrayRange(input), destMultiArray(result), &sqrt); // deprecated API ```