Nathan
Nathan

Reputation: 61

matrix multiplication resulting in values greater than 255

If I am performing matrix multiplication on two 8UC1 images, or per element multiplication, what happens if one of the resulting pixel values is greater than 255? For example, if in image A a certain pixel has value 100, and in image B that same pixel has value 150 (for the per element multiplication case), then clearly 100*150 > 255 - so does that pixel simply get truncated to 255 value? And if so is there some transformation I can make to preserve that information without having it truncated?

Upvotes: 1

Views: 1043

Answers (1)

berak
berak

Reputation: 39796

opencv will saturate the result for a uchar img.

to avoid that, use e.g. the dtype flag in multiply and specify a type larger than your input

Mat a, b; //input, CV_8U
Mat c;    // output, yet unspecified

multiply( a,b, c, 1, CV_32S ); // c will be of int type, untruncated results 

Upvotes: 3

Related Questions