image_kmeans: Obtain the Matrix of the Segmented Image using K-means...

Description Usage Arguments Value Examples

View source: R/image_kmeans.R

Description

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.

Usage

1

Arguments

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.

Value

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.

Examples

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")

rwang14/implant documentation built on Sept. 6, 2020, 3:21 a.m.