First time here? Check out the FAQ!

Sorry, this content is no longer available

Ask Your Question
6

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

asked Jun 27 '12

icedecker gravatar image

updated Nov 30 '0

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;
    }
}
Preview: (hide)

1 answer

Sort by » oldest newest most voted
9

answered Jun 28 '12

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);
Preview: (hide)

Comments

Thank you very much, it worked!

icedecker gravatar imageicedecker (Jun 28 '12)edit

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

maizi gravatar imagemaizi (May 14 '14)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 (Jan 21 '17)edit

Question Tools

1 follower

Stats

Asked: Jun 27 '12

Seen: 12,608 times

Last updated: Sep 16 '15