MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / img_test_demo

Function img_test_demo

examples/image_processing/image_demo.cpp:35–87  ·  view source on GitHub ↗

Demonstrates various image manipulations.

Source from the content-addressed store, hash-verified

33
34// Demonstrates various image manipulations.
35static void img_test_demo() {
36 af::Window wnd("Image Demo");
37
38 // load convolution kernels
39 array gauss_k = array(5, 5, h_gauss);
40 array sobel_k = array(3, 3, h_sobel);
41
42 // load images
43 array img_gray = loadImage(ASSETS_DIR "/examples/images/trees_ctm.jpg",
44 false); // 1 channel grayscale [0-255]
45 array img_rgb =
46 loadImage(ASSETS_DIR "/examples/images/sunset_emp.jpg", true) /
47 255.f; // 3 channel RGB [0-1]
48
49 array rotatedImg = rotate(img_gray, Pi / 2, false) / 255.f;
50 // array thrs_img = (img_gray < 130.f).as(s32);
51 array thrs_img = (img_gray < 130.f).as(f32);
52
53 // rgb channels
54 array rr, gg, bb;
55 channel_split(img_rgb, rr, gg, bb);
56
57 // hsv channels
58 array hsv = colorSpace(img_rgb, AF_HSV, AF_RGB);
59 array hh, ss, vv;
60 channel_split(hsv, hh, ss, vv);
61
62 // image histogram equalization
63 array ihist = histogram(img_gray, 256, 0, 255);
64 array inorm = histEqual(img_gray, ihist) / 255.f;
65
66 array edge_det = abs(convolve(img_gray, sobel_k)) / 255.f;
67 array smt = convolve(img_gray, gauss_k) / 255.f;
68
69 while (!wnd.close()) {
70 wnd.grid(2, 4);
71
72 // image operations
73 wnd(0, 0).image(img_rgb, "Input Image");
74 wnd(1, 0).image(rotatedImg, "Rotate");
75
76 wnd(0, 1).image(ss, "Saturation");
77 wnd(1, 1).image(bb, "Blue Channel");
78
79 wnd(0, 2).image(smt, "Smoothing");
80 wnd(1, 2).image(thrs_img, "Binary Thresholding");
81
82 wnd(0, 3).image(inorm, "Histogram Equalization");
83 wnd(1, 3).image(edge_det, "Edge Detection");
84
85 wnd.show();
86 }
87}
88
89int main(int argc, char** argv) {
90 int device = argc > 1 ? atoi(argv[1]) : 0;

Callers 1

mainFunction · 0.85

Calls 14

loadImageFunction · 0.85
colorSpaceFunction · 0.85
histEqualFunction · 0.85
asMethod · 0.80
closeMethod · 0.80
gridMethod · 0.80
imageMethod · 0.80
showMethod · 0.80
channel_splitFunction · 0.70
arrayClass · 0.50
rotateFunction · 0.50
histogramFunction · 0.50

Tested by

no test coverage detected