Subtract images with opencv

I want to subtract two images. My problem is that the cvSub () function is saturated. I want to do this:

1) Convert source images to shades of gray.

2) Take grayscale images (values ​​from 0 to 255).

3) Subtract images (values ​​from -255 to 255) -> scaling issue with cvSub ().

4) Change the scale by multiplying by 0.5 and adding 128.

I thought about changing the gray image from 8 bits to 16 bits, but then everything got worse, and there were a lot of lines of code, and in the end it did not work.

+3
source share
2 answers

Using openCV, you can do the following:

  • (1 2) 0,5 . [0..127]
  • 1 128. [128..255]
  • 2 1

, , 8 . cvConvertScale .

- :

//...
cvConvertScale(src1, tmp1, 0.5, 128);
cvConvertScale(src2, tmp2, 0.5, 0);
cvSub(tmp1, tmp2, dst);

EDIT:

(), , . - . , . , .

, . 2, ( ) 0.5 . , 1.0. , 1 , Alexanders. 16 .

. :

:
(200-101)/2 = 99/2 = 49,5

Alexanders ( ):
(200 - 101)/2 = 99/2 = 49

( ):
(200/2) - (101/2) = 100 - 50 = 50

+5

8 16 . 255 , . 8 .

, , .

+1

Source: https://habr.com/ru/post/1763576/


All Articles