Ask Your Question
0

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

asked 2013-09-13 03:46:02 -0500

updated 2013-09-13 11:32:59 -0500

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 */ } }
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-09-13 04:28:31 -0500

Moster gravatar image

updated 2013-09-13 04:29:16 -0500

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.

edit flag offensive delete link more

Comments

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

Pascal66 gravatar imagePascal66 ( 2013-09-13 09:15:22 -0500 )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 ( 2013-09-13 12:29:33 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-09-13 03:46:02 -0500

Seen: 294 times

Last updated: Sep 13 '13