jwm
jwm

Reputation: 5030

Logical operations in OpenCV

Assume two Mat CV_8UC1 images, mask, and label, how to do the following operation in OpenCV (C++):

mask(label==5) = 255; // this is allowed in Matlab 

// or 

mask[label==5] = 255; // this is allowed in Python

Upvotes: 0

Views: 142

Answers (2)

Christoph Rackwitz
Christoph Rackwitz

Reputation: 15365

It's literally just...

mask.setTo(255, label == 5);

Second argument is the mask argument.

Upvotes: 3

beaker
beaker

Reputation: 16791

You could use inrange() with lowerb and upperb both set to 5,

or you could use compare() with src2 set to 5 and cmpop set to cv::CMP_EQ.

Both will set the output mask to be 255 where the values match.

Upvotes: 2

Related Questions