Ask Your Question

shinning91's profile - activity

2017-06-29 05:23:32 -0500 received badge  Popular Question (source)
2014-03-12 02:05:03 -0500 asked a question Equivalent code in Java replacing pixels

Is there any similar code in Java OpenCV that I could use to perform the similar task as the code below shows?

    cv::Mat rgb_image(height, width, CV_8UC3);
    cv::MatIterator_<cv::Vec3b> rgb_first = rgb_image.begin<cv::Vec3b>();
    cv::MatIterator_<cv::Vec3b> rgb_last = rgb_image.end<cv::Vec3b>();
    cv::MatConstIterator_<int> label_first = labels.begin<int>();

    cv::Mat centers_u8;
    centers.convertTo(centers_u8, CV_8UC1, 255.0);
    cv::Mat centers_u8c3 = centers_u8.reshape(3);

    while ( rgb_first != rgb_last ) {
            const cv::Vec3b& rgb = centers_u8c3.ptr<cv::Vec3b>(*label_first)[0];
            *rgb_first = rgb;

Thanks in advance

2014-03-10 03:19:34 -0500 received badge  Editor (source)
2014-03-10 02:05:45 -0500 asked a question 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);

        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