#include <cmath>
#include <cstdio>
#include <cstdlib>
array hurl(
const array &in,
int randomization,
int repeat) {
float f = randomization / 100.0f;
int dim = (int)(f * w * h);
array temp = moddims(ret_val, w * h, 3);
for (int i = 0; i < repeat; ++i) {
array idxs = (w * h) * randu(dim);
array rndR = 255.0f * randu(dim);
array rndG = 255.0f * randu(dim);
array rndB = 255.0f * randu(dim);
temp(idxs, 0) = rndR;
temp(idxs, 1) = rndG;
temp(idxs, 2) = rndB;
}
ret_val = moddims(temp, in.
dims());
return ret_val;
}
array getRandomNeighbor(
const array &in,
int windW,
int windH) {
array vx = tile(sx, 1, in.
dims(1)) + floor(rnd * windW);
array vy = tile(sy.
T(), in.
dims(0), 1) + floor(rnd * windH);
return moddims(in2(vyy * in.
dims(0) + vxx, span), in.
dims());
}
array spread(
const array &in,
int window_width,
int window_height) {
return getRandomNeighbor(in, window_width, window_height);
}
array pick(
const array &in,
int randomization,
int repeat) {
float f = randomization / 100.0f;
int dim = (int)(f * w * h);
for (int i = 0; i < repeat; ++i) {
array rnd = getRandomNeighbor(ret_val, 1, 1);
temp_dst(idxs, span) = temp_src(idxs, span);
}
return ret_val;
}
static float h1[] = {1, 1, 1};
static float h2[] = {-1, 0, 1};
}
}
void normalizeImage(
array &in) {
float min = af::min<float>(in);
float max = af::max<float>(in);
in = 255.0f * ((in -
min) / (max - min));
}
array DifferenceOfGaussian(
const array &in,
int window_radius1,
int window_radius2) {
int w1 = 2 * window_radius1 + 1;
int w2 = 2 * window_radius2 + 1;
normalizeImage(ret_val);
return ret_val;
}
array medianfilter(
const array &in,
int window_width,
int window_height) {
ret_val(span, span, 0) =
medfilt(in(span, span, 0), window_width, window_height);
ret_val(span, span, 1) =
medfilt(in(span, span, 1), window_width, window_height);
ret_val(span, span, 2) =
medfilt(in(span, span, 2), window_width, window_height);
return ret_val;
}
array gaussianblur(
const array &in,
int window_width,
int window_height,
double sigma) {
}
array emboss(
const array &input,
float azimuth,
float elevation,
float depth) {
if (depth < 1 || depth > 100) {
printf("Depth should be in the range of 1-100");
return input;
}
static float x[3] = {-1, 0, 1};
else
in = input;
float phi = elevation *
af::Pi / 180.0f;
float theta = azimuth *
af::Pi / 180.0f;
float pos[3];
pos[0] = 255.99f *
cos(phi) *
cos(theta);
pos[1] = 255.99f *
cos(phi) *
sin(theta);
pos[2] = 255.99f *
sin(phi);
float pxlz = (6 * 255.0f) / depth;
array vdot = gx * pos[0] + gy * pos[1] + pxlz * pos[2];
array outwd = vdot < 0.0f;
array color = outwd * 0.0f + (1 - outwd) * norm;
return color;
}
int main(int argc, char **argv) {
try {
int device = argc > 1 ? atoi(argv[1]) : 0;
loadImage(ASSETS_DIR
"/examples/images/vegetable-woman.jpg",
true);
array prew_mag, prew_dir;
prewitt(prew_mag, prew_dir, img1ch);
sobelFilter(sob_mag, sob_dir, img1ch);
array sprd = spread(img, 3, 3);
array hrl = hurl(img, 10, 1);
array pckng = pick(img, 40, 2);
array difog = DifferenceOfGaussian(img, 1, 2);
array mf = medianfilter(hrl, 5, 5);
array gb = gaussianblur(hrl, 3, 3, 0.8);
array emb = emboss(img, 45, 20, 10);
printf("Press ESC while the window is in focus to exit\n");
while (!wnd.close()) {
wnd.grid(2, 5);
wnd(0, 0).image(hrl / 255, "Hurl noise");
wnd(1, 0).image(gb / 255, "Gaussian blur");
wnd(0, 1).image(bil / 255, "Bilateral filter on hurl noise");
wnd(1, 1).image(mf / 255, "Median filter on hurl noise");
wnd(0, 2).image(prew_mag / 255, "Prewitt edge filter");
wnd(1, 2).image(sob_mag / 255, "Sobel edge filter");
wnd(0, 3).image(sprd / 255, "Spread filter");
wnd(1, 3).image(pckng / 255, "Pick filter");
wnd(0, 4).image(difog / 255,
"Difference of gaussians(3x3 and 5x5)");
wnd(1, 4).image(emb / 255, "Emboss effect");
wnd.show();
}
fprintf(stderr,
"%s\n", e.
what());
throw;
}
return 0;
}
Window object to render af::arrays.
A multi dimensional data container.
dim4 dims() const
Get dimensions of the array.
array T() const
Get the transposed the array.
dim_t elements() const
Get the total number of elements across all dimensions of the array.
array copy() const
Perform deep copy of the array.
An ArrayFire exception class.
virtual const char * what() const
Returns an error message for the exception in a string format.
seq is used to create sequences for indexing af::array
AFAPI array atan2(const array &lhs, const array &rhs)
C++ Interface to evaluate the inverse tangent of two arrays.
AFAPI array cos(const array &in)
C++ Interface to evaluate the cosine function.
AFAPI array hypot(const array &lhs, const array &rhs)
C++ Interface to calculate the length of the hypotenuse of two inputs.
AFAPI array sin(const array &in)
C++ Interface to evaluate the sine function.
AFAPI 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.
AFAPI void setDevice(const int device)
Sets the current device.
AFAPI array bilateral(const array &in, const float spatial_sigma, const float chromatic_sigma, const bool is_color=false)
C++ Interface for bilateral filter.
AFAPI array colorSpace(const array &image, const CSpace to, const CSpace from)
C++ Interface wrapper for colorspace conversion.
AFAPI array gaussianKernel(const int rows, const int cols, const double sig_r=0, const double sig_c=0)
C++ Interface for generating gausian kernels.
AFAPI array medfilt(const array &in, const dim_t wind_length=3, const dim_t wind_width=3, const borderType edge_pad=AF_PAD_ZERO)
C++ Interface for median filter.
AFAPI void sobel(array &dx, array &dy, const array &img, const unsigned ker_size=3)
C++ Interface for extracting sobel gradients.
AFAPI array loadImage(const char *filename, const bool is_color=false)
C++ Interface for loading an image.
AFAPI double norm(const array &in, const normType type=AF_NORM_EUCLID, const double p=1, const double q=1)
C++ Interface to find the norm of a matrix.
AFAPI array moddims(const array &in, const dim4 &dims)
C++ Interface to modify the dimensions of an input array to a specified shape.
AFAPI array randu(const dim4 &dims, const dtype ty, randomEngine &r)
C++ Interface to create an array of random numbers uniformly distributed.
AFAPI array max(const array &in, const int dim=-1)
C++ Interface to return the maximum along a given dimension.
AFAPI array min(const array &in, const int dim=-1)
C++ Interface to return the minimum along a given dimension.
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.