Ask Your Question

Revision history [back]

Apply a function to a Mat (like filter2D or map in other language)

Is there a more efficient way than :

Mat mR = new Mat();
    Mat mG = new Mat();
    Mat mB = new Mat(); 
    Core.extractChannel(rgb, mR, 0); mR.convertTo(mR, CvType.CV_64FC1);
    Core.extractChannel(rgb, mG, 1); mG.convertTo(mG, CvType.CV_64FC1);
    Core.extractChannel(rgb, mB, 2); mB.convertTo(mB, CvType.CV_64FC1);
    int size = (int) (mG.total());
    double[] dR = new double[size]; mR.get(0, 0, dR);
    double[] dG = new double[size]; mG.get(0, 0, dG);
    double[] dB = new double[size]; mB.get(0, 0, dB);

    for (int i = size; i-- > 0;) {
        my_function(new Scalar(dR[i],dG[i],dB[i]));     
    }
    mR.put(0, 0, dR);
    mG.put(0, 0, dG);
    mB.put(0, 0, dB);

    mR.convertTo(mR, CvType.CV_8UC1); Core.insertChannel(mR, rgb, 0);
    mG.convertTo(mG, CvType.CV_8UC1); Core.insertChannel(mG, rgb, 1);
    mB.convertTo(mB, CvType.CV_8UC1); Core.insertChannel(mB, rgb, 2);
click to hide/show revision 2
retagged

updated 2013-09-30 03:00:00 -0600

berak gravatar image

Apply a function to a Mat (like filter2D or map in other language)

Is there a more efficient way than :

Mat mR = new Mat();
    Mat mG = new Mat();
    Mat mB = new Mat(); 
    Core.extractChannel(rgb, mR, 0); mR.convertTo(mR, CvType.CV_64FC1);
    Core.extractChannel(rgb, mG, 1); mG.convertTo(mG, CvType.CV_64FC1);
    Core.extractChannel(rgb, mB, 2); mB.convertTo(mB, CvType.CV_64FC1);
    int size = (int) (mG.total());
    double[] dR = new double[size]; mR.get(0, 0, dR);
    double[] dG = new double[size]; mG.get(0, 0, dG);
    double[] dB = new double[size]; mB.get(0, 0, dB);

    for (int i = size; i-- > 0;) {
        my_function(new Scalar(dR[i],dG[i],dB[i]));     
    }
    mR.put(0, 0, dR);
    mG.put(0, 0, dG);
    mB.put(0, 0, dB);

    mR.convertTo(mR, CvType.CV_8UC1); Core.insertChannel(mR, rgb, 0);
    mG.convertTo(mG, CvType.CV_8UC1); Core.insertChannel(mG, rgb, 1);
    mB.convertTo(mB, CvType.CV_8UC1); Core.insertChannel(mB, rgb, 2);

Apply a function to a Mat (like filter2D or map in other language)

Is there a more efficient way than :

Mat mR = new Mat();
    Mat mG = new Mat();
    Mat mB = new Mat(); 
    Core.extractChannel(rgb, mR, 0); mR.convertTo(mR, CvType.CV_64FC1);
    Core.extractChannel(rgb, mG, 1); mG.convertTo(mG, CvType.CV_64FC1);
    Core.extractChannel(rgb, mB, 2); mB.convertTo(mB, CvType.CV_64FC1);
    int size = (int) (mG.total());
    double[] dR = new double[size]; mR.get(0, 0, dR);
    double[] dG = new double[size]; mG.get(0, 0, dG);
    double[] dB = new double[size]; mB.get(0, 0, dB);

    for (int i = size; i-- > 0;) {
        my_function(new Scalar(dR[i],dG[i],dB[i]));     
    }
    mR.put(0, 0, dR);
    mG.put(0, 0, dG);
    mB.put(0, 0, dB);

    mR.convertTo(mR, CvType.CV_8UC1); Core.insertChannel(mR, rgb, 0);
    mG.convertTo(mG, CvType.CV_8UC1); Core.insertChannel(mG, rgb, 1);
    mB.convertTo(mB, CvType.CV_8UC1); Core.insertChannel(mB, rgb, 2);
click to hide/show revision 4
retagged

updated 2013-09-30 06:13:06 -0600

berak gravatar image

Apply a function to a Mat (like filter2D or map in other language)

Is there a more efficient way than :

Mat mR = new Mat();
    Mat mG = new Mat();
    Mat mB = new Mat(); 
    Core.extractChannel(rgb, mR, 0); mR.convertTo(mR, CvType.CV_64FC1);
    Core.extractChannel(rgb, mG, 1); mG.convertTo(mG, CvType.CV_64FC1);
    Core.extractChannel(rgb, mB, 2); mB.convertTo(mB, CvType.CV_64FC1);
    int size = (int) (mG.total());
    double[] dR = new double[size]; mR.get(0, 0, dR);
    double[] dG = new double[size]; mG.get(0, 0, dG);
    double[] dB = new double[size]; mB.get(0, 0, dB);

    for (int i = size; i-- > 0;) {
        my_function(new Scalar(dR[i],dG[i],dB[i]));     
    }
    mR.put(0, 0, dR);
    mG.put(0, 0, dG);
    mB.put(0, 0, dB);

    mR.convertTo(mR, CvType.CV_8UC1); Core.insertChannel(mR, rgb, 0);
    mG.convertTo(mG, CvType.CV_8UC1); Core.insertChannel(mG, rgb, 1);
    mB.convertTo(mB, CvType.CV_8UC1); Core.insertChannel(mB, rgb, 2);