Ask Your Question

How to Use formula in c++ opencv

asked 2017-06-29 01:53:01 -0500

jjabaram gravatar image

updated 2017-06-29 02:29:39 -0500

I have 3 formula, (P and S is the same picture that taken with different method)

  1. P/S
  2. P/(P+S)
  3. |P-S|/|P+S|

Image P

image description

Image S

image description

and with one of these formula the result will become like this :

image description

how to implemet these formula in c++ ?

if i`m using

subtract(P, S, min); 
add(P, S, plus);`

is that same as P-S and P+S, and how to divide P with S ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-06-29 02:18:53 -0500

LBerger gravatar image

When you use subtract or add you should use four parameters:

subtract(P, S, min, noArray(),CV_32F); 
add(P, S, plus, noArray(),CV_32F);

All pixels values are float (CV_32F) then you can use divide :


here you don't need CV_32F because result type will be same type that min or plus.

If you want to display results you will have to convert it to CV_8U. you can use normalize


PS variable name min is not very good

edit flag offensive delete link more


Thank you for your answer @LBerger, I'm new to OpenCV , can you please explain what is noArray(), CV_32F and CV_8U does? and can you also explain about normalize and the parameters thank you very much.

jjabaram gravatar imagejjabaram ( 2017-06-29 02:44:19 -0500 )edit
  • noArray() ... as name suggests an empty Array, placeholder if you dont need it more or less
  • CV_8U & CV_32F ... is the type of the matrix ... eg.: CV_8UC1 is unsigned char 1 channel image ... data will range from 0 to 255. Here you will see all openCV data types and their meaning.
  • stating @LBerger - If you want to display results you will have to convert it to CV_8U
Ice_T02 gravatar imageIce_T02 ( 2017-06-29 02:57:09 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-06-29 01:53:01 -0500

Seen: 68 times

Last updated: Jun 29 '17