Ask Your Question
0

Basic add and subtract on different size image

asked 2017-06-28 21:37:33 -0600

jjabaram gravatar image

First i want to appologize.

I`m new to opencv. currently I try to practice with basic stuff. i try to add and subtract 2 image

First Image :

image description

Second Image :

image description

Third Image :

image description

when I try to add and subtract First and Second Image i got result :

Add

image description

Subtract

image description

My question Is :

can someone explain to me

1.why First Image + Second Image become brighter

2.why First Image - Second Image become dark

3.when i try to do add and subtract to FIrst Image + Third Image i got an error, why ? (I try search it and i found CV_32F ,CV_32FC1 what is that ?)

4.when i try to add and subtract same size image, but the image in greyscale i got an error too, why ?

Thank you.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2017-06-29 06:03:25 -0600

KjMag gravatar image

updated 2017-06-29 06:11:51 -0600

  1. This is because you've simply added the values of the pixels without normalizing it, so if you had two corresponding pixels that were identical, now their value is twice as high as before. You need to normalize the image.

  2. This is because these two images are almost identical as far as I can tell, so if you subtract them, most of the values become 0. It's like with 'normal' subtraction - subtracting equal values always results in 0.

  3. Which error? Hard to tell without you showing the error message, but if you've uploaded original images, it's because of size mismatch. You can't add/subtract two images if their height and width don't match as it is a per-element operation. CV_32F has probably nothing to do with it unless you also have a type mismatch in your code (see below).

  4. If you try to add/subtract images of different types, e.g. one is grayscale, and the other one is RGB, it's type mismatch. For most operations, images have to be of the same type.

CV_32F etc. indicates the type of values that a particular Mat object uses to represent its data. The types usually have to match as mentioned at point 4. Here is a nice table showing how these types correspond to traditional variable types:

https://ninghang.blogspot.com/2012/11...

edit flag offensive delete link more

Comments

Thank you for your answer @KjMag. can you please explain to me what is different C1,C2,C3,C4. Thank you

jjabaram gravatar imagejjabaram ( 2017-06-29 21:05:12 -0600 )edit

C1, C2... etc. is the number of channels, e.g. RGB image has 3 channels (R, G and B) whereas a greyscale image has only one. You can append this C1, C2... etc. at the end of each type to indicate how many channels you want your matrix to have.

KjMag gravatar imageKjMag ( 2017-06-30 05:09:08 -0600 )edit
-1

answered 2017-06-29 07:31:08 -0600

nji gravatar image

And with bDetection = true, you get for Add: image description

and Sub:

image description

edit flag offensive delete link more

Comments

What is bDetection?

LBerger gravatar imageLBerger ( 2017-06-29 07:40:12 -0600 )edit

bananaDetection, one of the more sophisticated algs of opencv

nji gravatar imagenji ( 2017-06-29 08:26:33 -0600 )edit

The user question is about how to add two images, not how to detect banana.

LBerger gravatar imageLBerger ( 2017-06-29 08:37:21 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-06-28 21:37:33 -0600

Seen: 3,097 times

Last updated: Jun 29 '17