Question: Segmentation by Clustering USE C++ How could this been done using C++, like what would be a starting point as I'm a bit confused with

Segmentation by Clustering

USE C++

How could this been done using C++, like what would be a starting point as I'm a bit confused with the use of k-means

Any help would be appreciated!

Take a photo of your hand under "ideal" conditions, to capture correctly all shape details/proportions; think: surface/background, lighting, off-plane rotations, percentage of hand region with respect to the overall image. Most likely you will need to go the "trial-and-error" way.

2. Using iterative k-means, as described below and in the lecture slides/recording, cluster the hand image pixels with respect to {R,G,B} color; k (number of clusters) should be an input parameter (to be set by the user). Iterative k-means should run at least 100 times (with 100 different initializations). Again, with trial-and-error, choose "the best" k value for segmenting the hand. How? By running k-means once with a random initialization (non-iterative) and observing the result; if the chosen k value is acceptable, then run iterative k-means with this k value

Iterative k-means: In each execution (from start to convergence), k-means should use different randomly chosen centroids for initialization: each initialization is the color information of a randomly chosen pixel in the image; use a random integer generator to pick such initialization pixel among all pixels in the image. The output should be probability maps: e.g., for k=3, output should be three maps:

P(x belongs to k = i) | F ), for i={1,2,3}. F is the frequency of a pixel x assignment to a cluster, or, in other words, how salient the assignment of x to the i-th cluster is, or even how often a pixel "jumps" to a different cluster. So, each of the calculated maps (one for each cluster "identity"), indicates how often each pixel is assigned to the given cluster. To convert into probability, you will need to normalize into [0,1].

Example of iterative k-means:

step 1: load image into variable X (of size h x w x 3)

step 1.5: numofexec = 1 (counts how many times you execute k-means; initialize to 1)

step 2: randomly choose three pixels and use their color as initialization in the color space; i.e., {C1, C2, C3} for k = 3, where C1, C2, C3 are 3x1 (or 1x3) matrices.

step 3: perform k-means: Xout = somekmeansfun(X, k, C1, C2, C3) ==> notice the input: variable k, and random centroids ==> let the user define k prior to step 1. The output Xout should be of size h x w x 1. For more compact representation (see below), M( : , : , numofexec) = Xout. See notes below.

step 4: numofexec = numofexec + 1; Repeat step 2 ; repeat step 3.

step 5: At the end, you will have a 3-dimensional matrix M: size(M) = [h, w, numofexec]. You can visualize the cluster assignments of the pixel X(i, j) as: v = M(i, j, :) ==> size(v) = [1, numofexec] (1 x numofexec) ==> plot it. For each pixel, you can calculate the frequency of its assignment to each cluster using v.

Notes:

-- steps 2-4 should be in a for-loop.

-- in each exec., the cluster numbers may change: you need to reassign numbers based on the centroid values (e.g., use as reference the value of a chromatic component). For example: the "deep red" (high R-values, very low G,B-values) cluster may be labeled as "1" in one k-means execution, and as "2" in another execution; you will have to align/readjust those cluster number after each k-means execution.

-- to randomly choose centroid values, you can use a random integer generator that will be sampling the image pixels.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!