Ask Your Question
0

Broadcast single channel to N-channels

asked 2020-03-04 16:03:48 -0600

Is there an OpenCV function to take a single channel image and extend it to N-channels, copying/repeating the pixel value to all channels, something like a pixel-wise broadcast?

I need to be able to per-element multiply a single channel image with an n-channel image and the only way to do this with high-level function calls is to extend/repeat the single channel image to match the dimensions of my n-channel image. Can I achieve this with a cv::Mat from cv::Mat::reshape() passed to cv::repeat()? Can I achieve this with cv::transform()?

edit retag flag offensive close merge delete

Comments

cv::mixChannels()?

Der Luftmensch gravatar imageDer Luftmensch ( 2020-03-04 16:09:55 -0600 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2020-06-11 14:54:02 -0600

I solved this using cv::transform(), see the example below to extend the single_channel image to n channels.

cv::Mat broadcast = cv::Mat::ones(n, 1, single_channel.depth());
cv::Mat extended;
cv::transform(single_channel, extended, broadcast);

See cv::transform().

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-03-04 16:03:48 -0600

Seen: 1,847 times

Last updated: Jun 11 '20