#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};
}
return f * e;
}
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;
}
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;
int N = 2 * slices - 1;
int iter = 0;
for (int i = 0; !wnd.close(); i++) {
iter++;
int j = i % N;
int k = std::min(j, N - j);
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.
A multi dimensional data container.
dim4 dims() const
Get dimensions of the array.
dtype type() const
Get array data type.
const array as(dtype type) const
Casts the array into another data type.
Generic object that represents size and shape.
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.
array abs(const array &in)
C++ Interface to calculate the absolute value.
array exp(const array &in)
C++ Interface to evaluate the exponential.
array pow(const array &base, const array &exponent)
C++ Interface to raise a base to a power (or exponent).
array sqrt(const array &in)
C++ Interface to evaluate the square root.
array constant(T val, const dim4 &dims, const dtype ty=(af_dtype) dtype_traits< T >::ctype)
C++ Interface to generate an array with elements set to a specified value.
void setDevice(const int device)
Sets the current device.
void sync(const int device=-1)
Blocks until the device is finished processing.
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.
array loadImage(const char *filename, const bool is_color=false)
C++ Interface for loading an image.
array moddims(const array &in, const dim4 &dims)
C++ Interface to modify the dimensions of an input array to a specified shape.
array max(const array &in, const int dim=-1)
C++ Interface to return the maximum along a given dimension.
array min(const array &in, const int dim=-1)
C++ Interface to return the minimum along a given dimension.
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.
seq span
A special value representing the entire axis of an af::array.