Ask Your Question
1

Java - Mat subtract returns all black image

asked 2019-06-13 14:45:48 -0600

generic27 gravatar image

In OpenCV Java, When I perform Core.subtract(next.clone(), previous.clone(), result);, My result is an all black image. Both the next Mat and the previous Mat have been converted to grayscale and also thresholded prior to the subtract operation. Why is this happening?

edit retag flag offensive close merge delete

Comments

what is the type of those Mat's ? (possible truncation)

berak gravatar imageberak ( 2019-06-13 15:10:54 -0600 )edit
1

Both are CV_8UC1, they are both Mats taken from the same video; where there is a heart rate like monitor for which I am trying to subtract every identical pixel and leave only the different pixels in the result mat.

generic27 gravatar imagegeneric27 ( 2019-06-13 15:24:50 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-06-13 23:51:29 -0600

berak gravatar image

cv::subtract() saturates the result, negative numbers will be truncated to 0.

to avoid this, try one of:

  • selecting a larger (and signed) result type: subtract(src,dst,result, CV_16S); for the further processing
  • use cv::absDiff() instead of subtract()
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-06-13 14:45:48 -0600

Seen: 1,091 times

Last updated: Jun 13 '19