Difference between revisions of "Function:Add"

From CUVI Wiki
(Created page with "__NOTOC__ Adds two images ===Function=== {| |style="font-size:150%;"| <syntaxhighlight lang="cpp"> CuviStatus add(CuviImage* srcImage1, CuviImage* srcImage2, ...")
 
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
Adds two images
Adds two images or adds a constant to each pixel of the image.
===Function===
====Function====
{|
{|
|style="font-size:150%;"|
|style="font-size:100%;"|
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
CuviStatus add(CuviImage* srcImage1,
CuviStatus add(const CuviImage& src1,
               CuviImage* srcImage2,
               const CuviImage& src2,
               CuviImage* dstImage,
               CuviImage& dst,
               CuviStream* stream = NULL);
               const CuviStream& stream = CuviStream());
 
CuviStatus add(const CuviImage& src,
              const CuviScalar& values,
              CuviImage& dst,
              const CuviStream& stream = CuviStream());
 
CuviStatus add(const CuviImage& src,
              const Cuvi64f value,
              CuviImage& dst,
              const CuviStream& stream = CuviStream());
 
</syntaxhighlight>
</syntaxhighlight>
|}
|}
===Parameters===


__NOTOC__
====Parameters====
{|
|style="font-size:75%;"|
{|class="wikitable"
{|class="wikitable"
|-
|-
Line 19: Line 33:
! Description
! Description
|-
|-
| srcImage1
| src1
| CuviImage*
| CuviImage&
| First Input Image
| First Input Image
|-
|-
| srcImage2
| src2
| CuviImage*
| CuviImage&
| Second Input Image
| Second Input Image
|-
|-
| dstImage
| dst
| CuviImage*
| CuviImage&
| Resultant Image
| Resultant Image
|-
|-
| stream  
| stream  
| CuviStream*
| CuviStream&
| GPU stream ID for execution
| GPU stream ID for execution
 
|}
|}
|}


===Image Type Support===
===Image Type Support===
 
{|
|style="font-size:75%;"|
{| class="wikitable"
{| class="wikitable"
|-
|-
Line 48: Line 63:
| 8u
| 8u
| 8u
| 8u
|-
| 16u
| 16u
| 16u
|-
| 32f
| 32f
| 32f
|-
|-
| 8u
| 8u
| 8u
| 8u
| 16u
| 16u
|-
| 8u
| 8u
| 32f
|-
|-
| 16u
| 16u
| 16u
| 16u
| 16u
|-
| 32f
| 32f
| 32f
| 32f
|}
|}
===Sample===
{|
|-
|[[File:Addin1.jpg|frame|First Input Image]]
|[[File:Addin2.jpg|frame|Second Input Image]]
|[[File:AddOut.jpg|frame| Resultant Image]]
|}
|}


====Sample====
[[File:Addin1.jpg|none|frame|First Input Image]]
<br/>
[[File:Addin2.jpg|none|frame|Second Input Image]]
<br/>
[[File:AddOut.jpg|none|frame|Resultant Image]]
<br/>


===Example===
====Example====
{|
{|
|style="font-size:150%;"|
|style="font-size:100%;"|
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">


CuviImage* gimg1 = new CuviImage(size,img1->depth,img1->nChannels);
CuviImage gimg1 = cuvi::io::loadImage(path);
CuviImage* gimg2 = new CuviImage(size,img2->depth,img2->nChannels);
CuviImage gimg2 = cuvi::io::loadImage(path);
CuviImage* gout = new CuviImage(size,img2->depth,img2->nChannels);
CuviImage gout;


//Upload input data
//Add
gimg1->upload(img1->imageData,img1->widthStep);
cuvi::arithmeticLogical::add(gimg1,gimg2,gout);
gimg2->upload(img2->imageData,img2->widthStep);


//Add
//The same can be achieved by using arithmetic operators
cuvi::arithmeticAndLogical::add(gimg1,gimg2,gout);
gout = gimg1 + gimg2;
 
//Add a constant value to each pixel of the image
gimg1 += 10;
 
//Add a different value to each channel
gimg2 += CuviScalar(5,10,3);


</syntaxhighlight>
</syntaxhighlight>
|}
|}

Latest revision as of 15:09, 7 November 2022

Adds two images or adds a constant to each pixel of the image.

Function

CuviStatus add(const CuviImage& src1,
               const CuviImage& src2,
               CuviImage& dst,
               const CuviStream& stream = CuviStream());

CuviStatus add(const CuviImage& src,
               const CuviScalar& values,
               CuviImage& dst,
               const CuviStream& stream = CuviStream());

CuviStatus add(const CuviImage& src,
               const Cuvi64f value,
               CuviImage& dst,
               const CuviStream& stream = CuviStream());


Parameters

Name Type Description
src1 CuviImage& First Input Image
src2 CuviImage& Second Input Image
dst CuviImage& Resultant Image
stream CuviStream& GPU stream ID for execution

Image Type Support

Input 1 Input 2 Output
8u 8u 8u
16u 16u 16u
32f 32f 32f
8u 8u 16u
8u 8u 32f
16u 16u 32f

Sample

Error creating thumbnail: Unable to save thumbnail to destination
First Input Image


Error creating thumbnail: Unable to save thumbnail to destination
Second Input Image


Error creating thumbnail: Unable to save thumbnail to destination
Resultant Image


Example

CuviImage gimg1 = cuvi::io::loadImage(path);
CuviImage gimg2 = cuvi::io::loadImage(path);
CuviImage gout;

//Add	
cuvi::arithmeticLogical::add(gimg1,gimg2,gout);

//The same can be achieved by using arithmetic operators
gout = gimg1 + gimg2;

//Add a constant value to each pixel of the image
gimg1 += 10;

//Add a different value to each channel
gimg2 += CuviScalar(5,10,3);