Description Usage Arguments Value Examples
This function is to obtain a segmented plant image using K-means Clustering Method, together with the means and standard deviations of the pixel intensities for different classes.
1 | image_kmeans(Y, k)
|
Y |
an input matrix. For plant segmentation, we recommend to use the relative green intensity of the image. |
k |
a positive integer, which refers to the cluster number. In default, k = 2 to seperate the plant from the background. |
X |
a matrix of the class label of the segmented image. |
mu |
a k by 1 matrix. Each row represents the sample mean of each cluster. |
sigma |
a k by 1 matrix. Each row represents the sample standard deviation of each cluster. |
1 2 3 4 5 6 7 8 9 | library(png)
orig = readPNG(system.file("extdata", "reduced.png", package = "implant", mustWork = TRUE))
#Define the response as relative green.
Y = orig[ , , 2]/(orig[ , , 1]+orig[ , , 2]+orig[ , , 3])
#Take the initial label of EM algorithm using K-means
X = image_kmeans(Y, k = 2)$X
#Obtain the image produced by kmeans clustering
output = matrix(as.numeric(X), nrow = nrow(X), ncol = ncol(X)) - 1
writePNG(output,"~/kmeans.png")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.