Ask Your Question
6

How to read the pixels of the three channels at the same time?

asked 2012-06-27 16:22:41 -0600

icedecker gravatar image

updated 2020-11-30 03:00:36 -0600

Hi, I'm trying to convert the following C++ code in Java (for an Android app). I need to sum the pixels in the three channels at the same time (and others operations). Any suggestions?

vector<Mat> channel; // in java List<Mat> channel = null;
split(img, channel); // in java org.opencv.core.Core.split(img, channel);

// sum the pixels of three channels - How to do it in Java? The it_r, it_g and it_b are iterators
for (; it_r != it_endr; ++it_r, ++it_g, ++it_b) {
    r = (double) *it_r;
    g = (double) *it_g;
    b = (double) *it_b;

    tmp = r + g + b;
    if (tmp > sum) {
        sum = tmp;
    }
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
9

answered 2012-06-28 08:23:41 -0600

Andrey Pavlenko gravatar image
Mat mRgb = ...
List<Mat> lRgb = new ArrayList<Mat>(3);
Core.split(mRgb, lRgb);
Mat mR = lRgb.get(0);
Mat mG = lRgb.get(1);
Mat mB = lRgb.get(2);
Mat mSum = new Mat();
Mat mEmpty = new Mat();
Core.add(mR,   mG, mSum, mEmpty, CvType.CV_16UC1);
Core.add(mSum, mB, mSum, mEmpty, CvType.CV_16UC1);
double maxSum = Core.norm(mSum, Core.NORM_INF);
edit flag offensive delete link more

Comments

Thank you very much, it worked!

icedecker gravatar imageicedecker ( 2012-06-28 11:18:36 -0600 )edit

why my Eclipse can't recognize the "CV_16UC1" ?

maizi gravatar imagemaizi ( 2014-05-14 08:01:50 -0600 )edit

Hello Sir, I tried your code in my Android application in Java using openCv library, it did not work, I just wanted to split the colorful bitmap image into its three different rgb channel images. It will be so great if you could help me in this situation.

khatri.kelash gravatar imagekhatri.kelash ( 2017-01-21 11:27:51 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2012-06-27 16:22:41 -0600

Seen: 12,490 times

Last updated: Sep 16 '15