<< add Image operations convertScaleAbs >>

scicv >> Image operations > addWeighted

addWeighted

Calculates the weighted sum of two images

Syntax

img_out = addWeighted(img1, alpha, img2, beta, gamma[, dtype])

Parameters

img1

First image (Mat).

alpha

Weight applied to the first image (double).

img2

Second image (Mat).

beta

Weight applied to the second image (double).

gamma

Scalar added to the sum (double).

dtype

Optional depth of the output image (double).

img_out

Output image (Mat).

Description

addWeighted computes the weighted sum of two images pixel per pixel as following:

$img = alpha*img1 + beta*img2 + gamma$

Examples

scicv_Init();

img = imread(getSampleImage("lena.jpg"), CV_LOAD_IMAGE_GRAYSCALE);

// First order derivative on x, kernel size 3
img_grad_x = Sobel(img, CV_16S, 1, 0, 3);
img_grad_abs_x = convertScaleAbs(img_grad_x);

// First order derivative on x, kernel size 3
img_grad_y = Sobel(img, CV_16S, 0, 1, 3);
img_grad_abs_y = convertScaleAbs(img_grad_y);

// Calculates the gradient image
img_grad = addWeighted(img_grad_abs_x, 0.5, img_grad_abs_y, 0.5, 0);
matplot(img_grad);

delete_Mat(img);
delete_Mat(img_grad_x);
delete_Mat(img_grad_abs_x);
delete_Mat(img_grad_y);
delete_Mat(img_grad_abs_y);
delete_Mat(img_grad);

See also


Report an issue
<< add Image operations convertScaleAbs >>