#include <string.h>
#include <stdio.h>
#include <math.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 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;
}
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;
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);
fprintf(stderr,
"%s\n", e.
what());
}
return 0;
}
Window object to render af::arrays.
Definition: graphics.h:37
A multi dimensional data container.
Definition: array.h:27
Definition: exception.h:20
virtual const char * what() const
Definition: exception.h:34
@ AF_COLORMAP_HEAT
Heat map.
Definition: defines.h:338
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)
dim4 dims() const
Get dimensions of the array.
dtype type() const
Get array data type.
const array as(dtype type) const
Converts the array into another type.
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.
Definition: algorithm.h:15
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.
Definition: opencl.h:329
Internal timer object.
Definition: timing.h:29