#include <math.h>
#include <stdio.h>
#include <string.h>
#include "../common/progress.h"
const float h_sx_kernel[] = {1, 2, 1, 0, 0, 0, -1, -2, -1};
const float h_sy_kernel[] = {-1, 0, 1, -2, 0, 2, -1, 0, 1};
static array kernelx =
array(dim4(3, 3), h_sx_kernel);
static array kernely =
array(dim4(3, 3), h_sy_kernel);
}
return f * e;
}
float mx = max<float>(I1);
float mn = min<float>(I1);
float u0 = 0.9 * mx;
float s0 = (mx - mn) / 2;
float u1 = 1.1 * mn;
float s1 = (mx - mn) / 2;
array L0 = gauss(I1, u0, s0);
array L11 = gauss(I1, u1, s1);
if (k == 0) {
L10 = L11;
} else {
L10 = L11_old;
L11 = L12_old;
}
if (k < A.dims(2) - 1) {
L12 = gauss(A(
span,
span, k + 1), u1, s1);
} else {
L12 = L11;
}
L11_old = L11;
L12_old = L12;
array L1 = (L10 + L11 + L12) / 3;
}
void brain_seg(bool console) {
double time_total = 30;
int slices = 256;
B =
moddims(B, dim4(B.dims(0), B.dims(1) / slices, slices));
int N = 2 * slices - 1;
timer t = timer::start();
int iter = 0;
for (int i = 0; !wnd.close(); i++) {
iter++;
int j = i % N;
array Si = segment_volume(B, k);
array Ei = edges_slice(Si);
if (!console) {
wnd.grid(2, 2);
wnd(0, 0).image(Bi / 255.f, "Input");
wnd(1, 0).image(Ei, "Edges");
wnd(0, 1).image(Mi / 255.f, "Meanshift");
wnd(1, 1).image(Si, "Segmented");
wnd.show();
} else {
}
if (!progress(iter, t, time_total)) break;
if (!(i < 100 * N)) break;
}
}
int main(int argc, char* argv[]) {
int device = argc > 1 ? atoi(argv[1]) : 0;
bool console = argc > 2 ? argv[2][0] == '-' : false;
try {
printf("Brain segmentation example\n");
brain_seg(console);
return 0;
}
Window object to render af::arrays.
const array as(dtype type) const
Casts the array into another data type.
An ArrayFire exception class.
virtual const char * what() const
Returns an error message for the exception in a string format.
@ AF_COLORMAP_HEAT
Heat map.
AFAPI array abs(const array &in)
C++ Interface for absolute value.
AFAPI array exp(const array &in)
C++ Interface for exponential of an array.
AFAPI array pow(const array &lhs, const array &rhs)
C++ Interface for power.
AFAPI array sqrt(const array &in)
C++ Interface for square root of input.
array constant(T val, const dim4 &dims, const dtype ty=(af_dtype) dtype_traits< T >::ctype)
AFAPI void setDevice(const int device)
Sets the current device.
AFAPI void sync(const int device=-1)
Blocks until the device is finished processing.
AFAPI array meanShift(const array &in, const float spatial_sigma, const float chromatic_sigma, const unsigned iter, const bool is_color=false)
C++ Interface for mean shift.
AFAPI array loadImage(const char *filename, const bool is_color=false)
C++ Interface for loading an image.
AFAPI array moddims(const array &in, const unsigned ndims, const dim_t *const dims)
static af::array array(af::dim4 idims, cl_mem buf, af::dtype type, bool retain=false)
Create an af::array object from an OpenCL cl_mem buffer.
AFAPI array min(const array &in, const int dim=-1)
C++ Interface for minimum values in an array.
AFAPI array convolve(const array &signal, const array &filter, const convMode mode=AF_CONV_DEFAULT, const convDomain domain=AF_CONV_AUTO)
C++ Interface for convolution any(one through three) dimensional signals.
struct af::timer timer
Internal timer object.
AFAPI seq span
A special value representing the entire axis of an af::array.