Thanks for reviving this good example ๐
Perhaps, we should use a smaller image size so that the example runs relatively fast on lower level NVIDIA/AMD GPUs.
I have tried few images from our examples-images-assets, spider.jpg(512x512) does perform faster and the banding that appears in the visual display after clustering is more evident with this image. I have changed the layout to 2x2 grid with 1024x1024 as window size to have better image display. Checkout the spider output with following changes and let me know.
diff --git a/examples/machine_learning/kmeans.cpp b/examples/machine_learning/kmeans.cpp index 81f1503a..e3a80018 100644 --- a/examples/machine_learning/kmeans.cpp +++ b/examples/machine_learning/kmeans.cpp @@ -113,7 +113,7 @@ int kmeans_demo(int k, bool console) { printf("** ArrayFire K-Means Demo (k = %d) **\n\n", k); array img = - loadImage(ASSETS_DIR "/examples/images/vegetable-woman.jpg", true) / + loadImage(ASSETS_DIR "/examples/images/spider.jpg", false) / 255; // [0-255] int w = img.dims(0), h = img.dims(1), c = img.dims(2); @@ -133,16 +133,16 @@ int kmeans_demo(int k, bool console) { array out_half = moddims(means_half(span, clusters_half, span), img.dims()); array out_dbl = moddims(means_dbl (span, clusters_dbl , span), img.dims()); - af::Window wnd("ArrayFire K-Means Demo"); - wnd.grid(1, 4); + af::Window wnd(1024, 1024, "ArrayFire K-Means Demo"); + wnd.grid(2, 2); std::string out_full_caption = "k = " + std::to_string(k); std::string out_half_caption = "k = " + std::to_string(k / 2); std::string out_dbl_caption = "k = " + std::to_string(k * 2); while (!wnd.close()) { wnd(0, 0).image(img, "Input Image"); wnd(0, 1).image(out_full, out_full_caption.c_str()); - wnd(0, 2).image(out_half, out_half_caption.c_str()); - wnd(0, 3).image(out_dbl, out_dbl_caption.c_str()); + wnd(1, 0).image(out_half, out_half_caption.c_str()); + wnd(1, 1).image(out_dbl, out_dbl_caption.c_str()); wnd.show(); } ``