Ask Your Question
5

how to sum a 3 channel matrix to a one channel matrix?

asked 2012-10-13 09:32:27 -0500

501 Not Implemented gravatar image

updated 2015-08-24 20:15:01 -0500

Hi, i want to sum a 3 channel (lab) matrix to a one channel matrix. Is there a simple way to do this or must i split the image into 3 different CvMat-Objects?

It would to be nice, if there is a parameter for cvCvtColor that add all 3 channels with the same weight.

greetings

edit retag flag offensive close merge delete

Comments

4 answers

Sort by ยป oldest newest most voted
4

answered 2015-06-16 15:15:06 -0500

Oliver Keller gravatar image

updated 2016-12-04 07:46:21 -0500

Adi gravatar image

Hi,

here's a code sample without cv::reshape() or cv::reduce() :

cv::transform(m_in, m_out, cv::Matx13f(1,1,1))

edit flag offensive delete link more
8

answered 2012-10-14 01:10:38 -0500

sammy gravatar image

updated 2012-10-14 01:11:53 -0500

You can reshape() it to a 3 cols* (initial_rows*initial_cols) rows, then use cv::reduce() by summing up the cols, then reshape it back to initial_rows-by-initial_cols. You won't need the split.

Note that reshape() does not reallocate or move elements, just inteprets their order in a different way, so it it very fast.

edit flag offensive delete link more

Comments

Hmm, I like this one.

Michael Burdinov gravatar imageMichael Burdinov ( 2012-10-14 02:17:50 -0500 )edit

great solution! thanks :)

501 Not Implemented gravatar image501 Not Implemented ( 2012-10-14 09:17:08 -0500 )edit

hi, Can anyone provide me small code sample to sum a 3 channel matrix into one channel matrix using reshape and reduce functions using the above idea which explained by sammy ....

Sharath gravatar imageSharath ( 2015-06-05 08:56:18 -0500 )edit
2

answered 2012-10-13 10:20:40 -0500

Rui Marques gravatar image

One way to do it would be to split the channels with split and to add them with addWeighted.

edit flag offensive delete link more

Comments

yeah in time i splitt the image and use the cvAdd-feature. i thought there is a faster method

501 Not Implemented gravatar image501 Not Implemented ( 2012-10-13 10:43:53 -0500 )edit
-1

answered 2012-10-14 03:25:20 -0500

rotating_image gravatar image

use cvMerge after converting the CvMat to CvArr

edit flag offensive delete link more

Comments

cvMerge is not performing sum operation. It is only rearranges data from multiple single-channel images to one multi-channel.

Michael Burdinov gravatar imageMichael Burdinov ( 2012-10-14 03:59:21 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2012-10-13 09:32:27 -0500

Seen: 8,584 times

Last updated: Dec 04 '16