image_processing/confidence_connected_components.cpp
/*******************************************************
* Copyright (c) 2019, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* https://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <arrayfire.h>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace af;
int main(int argc, char* argv[]) {
try {
unsigned radius = 3;
unsigned multiplier = 3;
int iter = 5;
array A = loadImage(ASSETS_DIR "/examples/images/donut.png", false);
unsigned seedx = 132;
unsigned seedy = 132;
array ring =
confidenceCC(A, 1, &seedx, &seedy, radius, multiplier, iter, 255);
seedx = 152;
seedy = 152;
array sxArr(dim4(1), &seedx);
array syArr(dim4(1), &seedy);
array core =
confidenceCC(A, sxArr, syArr, radius, multiplier, iter, 255);
seedx = 15;
seedy = 15;
unsigned seedcoords[] = {15, 15};
array seeds(dim4(1, 2), seedcoords);
array background =
confidenceCC(A, seeds, radius, multiplier, iter, 255);
af::Window wnd("Confidence Connected Components demo");
while (!wnd.close()) {
wnd.grid(2, 2);
wnd(0, 0).image(A, "Input");
wnd(0, 1).image(ring, "Ring Component - Seed(132, 132)");
wnd(1, 0).image(core, "Center Black Hole - Seed(152, 152)");
wnd(1, 1).image(background, "Background - Seed(15, 15)");
wnd.show();
}
} catch (af::exception& e) {
fprintf(stderr, "%s\n", e.what());
throw;
}
return 0;
}
af::dim4
Generic object that represents size and shape.
Definition: dim4.hpp:33
af::Window::image
void image(const array &in, const char *title=NULL)
Renders the input array as an image to the window.
af::array
A multi dimensional data container.
Definition: array.h:35
af
Definition: algorithm.h:15
af::Window::show
void show()
This function swaps the background buffer to current view and polls for any key strokes while the win...
af::Window::close
bool close()
Check if window is marked for close.
af::exception
An ArrayFire exception class.
Definition: exception.h:29
af::loadImage
AFAPI array loadImage(const char *filename, const bool is_color=false)
C++ Interface for loading an image.
arrayfire.h
af::exception::what
virtual const char * what() const
Returns an error message for the exception in a string format.
Definition: exception.h:60
af::Window
Window object to render af::arrays.
Definition: graphics.h:37
af::Window::grid
void grid(const int rows, const int cols)
Setup grid layout for multiview mode in a window.
af::confidenceCC
AFAPI array confidenceCC(const array &in, const array &seeds, const unsigned radius, const unsigned multiplier, const int iter, const double segmentedValue)
C++ Interface for confidence connected components.