Ask Your Question
0

How to operate on each pixel of a cv2.cv.Mat with a 3 x 3 matrix?

asked 2012-11-25 21:02:22 -0500

smcamp gravatar image

I want to operate on each bgr pixel of a CvMat with a (3 x 3) Miyazaki matrix (http://www.cg.info.hiroshima-cu.ac.jp/~miyazaki/knowledge/teche40.html).

I have tried various operations but I keep getting various errors.

Any help on what operation/syntax is needed would be greatly appreciated!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2012-11-26 07:46:12 -0500

AMP gravatar image

I think this code can help you!

Mat x,y,z;
x=Mat(image.at<cv::Vec3b>(i,j));
x.convertTo(y,c.type()); //c is your 3x3 matrix
z=c*y;
edit flag offensive delete link more

Comments

Thanks!

Im using Python and cv2 so I think I have to make a few modifications.

Does "x=Mat(image.at<cv::Vec3b>(i,j));" create a 3 x 1 matrix for each pixel?

Also does this snippet of code assume I am manually iterating over each pixel in the image or is there some built in function I haven't found that will automatically operate on every pixel?

Thanks,

Scott

smcamp gravatar imagesmcamp ( 2012-11-26 13:26:18 -0500 )edit

yes,it does create a 3x1 matrix.

you should manually iterate over each pixel by changing i & j in a for loop.

AMP gravatar imageAMP ( 2012-11-27 00:50:34 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2012-11-25 21:02:22 -0500

Seen: 405 times

Last updated: Nov 26 '12