Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

Subtracts pixel values of two images I2 = I1 - I2

Ladislav_K_
Beginner
626 Views

Hi,
Is there smart way how to subctract image I2 from I1 and place result in I2 ?

AFAIU in-place ippiSub can subtract I2 (pSsrc) from I1 (pSrcDst), but places result in I1 (pSrcDst).
When I use not-in-place subtraction and specify pSrc1=I2, pSrc2=I1, pDst=I2 will it work ? Or all 3 images must be distinct ?

Is there workaround ?

0 Kudos
3 Replies
Igor_A_Intel
Employee
626 Views

Hi Ladislav,

In general it is not good approach to use non-in-place functions (without suffix _I) in in-place mode, but for simple arithmetic it may work (guess it's clear that such approach will not work for filtering-like functions, that perform operation on neighbor pixels). To be consistent with IPP logic you can do this in 2 steps (and better to do this by slices and use slices of a bit less size than L1): SubCRev with C==0, then - in-place Add.

regards, Igor

0 Kudos
Ladislav_K_
Beginner
626 Views

Hi Igor,

When I use SubCRev with C==0 on _8u image I guess, that all pixels will be ==0 because all values becomes negative so they will be saturated to 0, does not ?

I have used:

      // subtract "src" from "dest" and store back to "src"
      ippiSub_8u_C1RSfs(src, srcStep, dest, destStep, src, srcStep, roiSize, 0);
      // in place multiply (can be used ippiMulC)
      ippiScaleC_8u_C1IR(src, srcStep, 0.5, 0, roiSize, ippAlgHintFast);
      // in place add to "dest"
      ippiAdd_8u_C1IRSfs(src, srcStep, dest, destStep, roiSize, 0);

which seems to work for me as expected.

0 Kudos
Igor_A_Intel
Employee
626 Views

You didn't say that you asked about 8u... Yes, result will be saturated. ScaleC may be useful from practical point of view, but it is rather slow in comparison with simple arithmetic for 8u data...

regards, Igor

0 Kudos
Reply