Ask Your Question
0

multiply image with scalar

asked 2018-03-30 22:39:56 -0600

julian403 gravatar image

updated 2018-03-30 23:26:17 -0600

Hello All.

Its possible this operation?;

    cv::Mat A 
    cv::Mat B 
    cv::Mat C
    A= imread(argv[1], CV_LOAD_IMAGE_COLOR);   // Read the file
    B = imread(argv[2], CV_LOAD_IMAGE_COLOR);   // Read the file
C = 5*A - 6*B

So, C will get the difference between A times 5 and B times 6. This is right? Does the matrix multiplication by scalar works fine in opencv?

I mean, for example

5*A

will it multiplicate every A pixel by 5?

I need this information because Im performing discrete filters

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-03-31 01:26:29 -0600

berak gravatar image

updated 2018-04-02 04:10:19 -0600

yes, you can do that, but you have to be careful with the type there.

if you read an image with imread(), the depth will be uchar and it's values in [0..255] range.

operations like adding or multiplying will get saturated, meaning, that 130*2 will be 255, not 260, and 17 *-1 will be 0, not -17

if you want to avoid the saturation, you have to convert your images to CV_32S (integer) or CV_32F (float).

edit flag offensive delete link more

Comments

1

Thanks a lot

julian403 gravatar imagejulian403 ( 2018-03-31 08:17:10 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-03-30 22:39:56 -0600

Seen: 10,113 times

Last updated: Apr 02 '18