Ask Your Question
0

How to mask only red channel_C++

asked 2018-07-30 04:28:33 -0500

JeyP4 gravatar image

How to mask only one channel, say only red channel. e.g.

Mat img = imread("Lena.jpg");
Mat mask = img[:, : , 2]>0;       // I want to do something like this
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-07-30 05:04:12 -0500

LBerger gravatar image

Use inrange :

    img = imread("g:/lib/opencv/samples/data/lena.jpg",IMREAD_COLOR);
    Mat mask;
    inRange(img, Vec3b(0, 0, 100), Vec3b(255, 255, 255), mask);

    img.copyTo(gray, mask);
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-07-30 04:28:33 -0500

Seen: 54 times

Last updated: Jul 30 '18