Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Problem in using K-means clustering an image using Java

Hi, I am currently trying to develop an Android app. I have tried to convert an image of a leaf from RBG to HSV to produce an image which is in saturation-value space (without hue). Next, I tried to use K-means to produce a image which suppose to look like this:

image description

However, I have no idea where to continue after I uses the K-means function in OpenCV. How do I display the results after K-means?

Imgproc.cvtColor(rgba, mHSV, Imgproc.COLOR_RGBA2RGB,3); Imgproc.cvtColor(rgba, mHSV, Imgproc.COLOR_RGB2HSV,3); List<mat> hsv_planes = new ArrayList<mat>(3); Core.split(mHSV, hsv_planes);

    Mat channel = hsv_planes.get(2);
    channel = Mat.zeros(mHSV.rows(),mHSV.cols(),CvType.CV_8UC1);
    hsv_planes.set(2,channel);
    Core.merge(hsv_planes,mHSV);



    Mat clusteredHSV = new Mat();
    mHSV.convertTo(mHSV, CvType.CV_32FC3);
    TermCriteria criteria = new TermCriteria(TermCriteria.EPS + TermCriteria.MAX_ITER,100,0.1);
    Core.kmeans(mHSV, 2, clusteredHSV, criteria, 10, Core.KMEANS_PP_CENTERS);

Below is the result I currently get:

image description

click to hide/show revision 2
retagged

updated 2014-03-10 02:09:30 -0600

berak gravatar image

Problem in using K-means clustering an image using Java

Hi, I am currently trying to develop an Android app. I have tried to convert an image of a leaf from RBG to HSV to produce an image which is in saturation-value space (without hue). Next, I tried to use K-means to produce a image which suppose to look like this:

image description

However, I have no idea where to continue after I uses the K-means function in OpenCV. How do I display the results after K-means?

Imgproc.cvtColor(rgba, mHSV, Imgproc.COLOR_RGBA2RGB,3); Imgproc.cvtColor(rgba, mHSV, Imgproc.COLOR_RGB2HSV,3); List<mat> hsv_planes = new ArrayList<mat>(3); Core.split(mHSV, hsv_planes);

    Mat channel = hsv_planes.get(2);
    channel = Mat.zeros(mHSV.rows(),mHSV.cols(),CvType.CV_8UC1);
    hsv_planes.set(2,channel);
    Core.merge(hsv_planes,mHSV);



    Mat clusteredHSV = new Mat();
    mHSV.convertTo(mHSV, CvType.CV_32FC3);
    TermCriteria criteria = new TermCriteria(TermCriteria.EPS + TermCriteria.MAX_ITER,100,0.1);
    Core.kmeans(mHSV, 2, clusteredHSV, criteria, 10, Core.KMEANS_PP_CENTERS);

Below is the result I currently get:

image description

Problem in using K-means clustering an image using Java

Hi, I am currently trying to develop an Android app. I have tried to convert an image of a leaf from RBG to HSV to produce an image which is in saturation-value space (without hue). Next, I tried to use K-means to produce a image which suppose to look like this:

image description

However, I have no idea where to continue after I uses the K-means function in OpenCV. How do I display the results after K-means?

 Imgproc.cvtColor(rgba, mHSV, Imgproc.COLOR_RGBA2RGB,3);
Imgproc.cvtColor(rgba, mHSV, Imgproc.COLOR_RGB2HSV,3);
List<mat> List<Mat> hsv_planes = new ArrayList<mat>(3);
ArrayList<Mat>(3);
 Core.split(mHSV, hsv_planes);

hsv_planes);
 Mat channel = hsv_planes.get(2);
 channel = Mat.zeros(mHSV.rows(),mHSV.cols(),CvType.CV_8UC1);
 hsv_planes.set(2,channel);
 Core.merge(hsv_planes,mHSV);
  Mat clusteredHSV = new Mat();
 mHSV.convertTo(mHSV, CvType.CV_32FC3);
  TermCriteria criteria = new TermCriteria(TermCriteria.EPS + TermCriteria.MAX_ITER,100,0.1);
  Core.kmeans(mHSV, 2, clusteredHSV, criteria, 10, Core.KMEANS_PP_CENTERS);

Below is the result I currently get:

image description