Ask Your Question
0

Best way to access pixel value from a single channel ? Transform to an array or use existing code ?

asked Sep 13 '13

updated Sep 13 '13

This one

Core.extractChannel(mRgba, mR, 0); // for R channel
imageSrc.convertTo(mR, CvType.CV_64FC1);
int size = (int) (mG.total());
double[] dR = new double[size];
mR.get(0, 0, dR);

for (int i = size; i-- > 0;) {
dR[i] = /** do the work */
}

Or accessing pixel value with for x and for y ? ".At" is not possible in java version of OpenCv 2.4.6 Other way (Moster)

width = mR.width(); height  = mR.height(); 
        byte[] bR = new byte{size]; 
        for (y= height , y-- >0;) for (x =with, y-- >0;) //Best to work with row 2 Best to decrease  counter  
    bR.get(y, x).val[0} = /** do the work */ } }
Preview: (hide)

1 answer

Sort by » oldest newest most voted
0

answered Sep 13 '13

Moster gravatar image

updated Sep 13 '13

This definitely depends on what you gonna do. If you only want to access 1 or 2 pixels (a small amount), it would be enough to use Mat.get(row, col). If you want to work on the whole Mat, you should use the way you already proposed with getting the Mat and transfering it into an buffer array.

Preview: (hide)

Comments

Who need to access of one or two pixel Moster ? question modified

Pascal66 gravatar imagePascal66 (Sep 13 '13)edit

I dont mean exactly 1-2, but only a small amount. If you need to acess all pixels and also often, your first method is definitely better. Accessing an array is faster than calling Mat.get in the long run.

Moster gravatar imageMoster (Sep 13 '13)edit

Question Tools

Stats

Asked: Sep 13 '13

Seen: 504 times

Last updated: Sep 13 '13