Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Peter_Hauge
Beginner
64 Views

Scaled subtraction

We are in the process of replacing another 3rd party image library with the functions made avialable through IPP, and are very happy with the performance and the suit of algorithms in IPP. However, we miss a single function, and wonder if it is simply not there or if we have missed it.

Is there a way to achieve a scaled subtraction of e.g. two BYTE images A and B so as to avoid saturation? The desired output would be Out := 128 + (A-B)/2. Normally, each pixel result would be coded like Out := (A+twos_complement(B))>>1. The same would be very nice for color images, but for a 3-channel BYTE color image the operation would be exactly the same. Of course, it would also be nice for 16- and 32-bit images.

What exactly does the 32-bit Complement function do? I do not understand the very short description in the help. Is it related to twos complement?

It does not seem straight-forward to obtain the scaled subtraction with the available scaled versions and the automatic saturation of the current arithmetic functions.

Any help will be appreciated.
Thanks, Peter.
0 Kudos
2 Replies
PaulF_IntelCorp
Employee
64 Views

Hello Peter,

I'm not sure I understand the Complement function, either, I'm still coming up to speed on the ippi* functions. It appears to be a special function for JPEG2000 encode and decode operations.

It sounds like the ippsSubC* functions might work for you (especially the sfs variants). Might require a little extra effort, depending on how your image data is laid out, but I think it provides the basic functionality you are looking for.

Paul
Peter_Hauge
Beginner
64 Views

Quoting - Peter Hauge
We are in the process of replacing another 3rd party image library with the functions made avialable through IPP, and are very happy with the performance and the suit of algorithms in IPP. However, we miss a single function, and wonder if it is simply not there or if we have missed it.

Is there a way to achieve a scaled subtraction of e.g. two BYTE images A and B so as to avoid saturation? The desired output would be Out := 128 + (A-B)/2. Normally, each pixel result would be coded like Out := (A+twos_complement(B))>>1. The same would be very nice for color images, but for a 3-channel BYTE color image the operation would be exactly the same. Of course, it would also be nice for 16- and 32-bit images.

What exactly does the 32-bit Complement function do? I do not understand the very short description in the help. Is it related to twos complement?

It does not seem straight-forward to obtain the scaled subtraction with the available scaled versions and the automatic saturation of the current arithmetic functions.

Any help will be appreciated.
Thanks, Peter.

Hi Paul,

Thanks for the quick reply. If you are right about the Complement-function we need not consider that anymore :). I am afraid that SubC won't do. It appears that the ipps-functions are pretty much overlapping with the ippi-functions, so I will refer to those instead. ippiSubC is used when one argument is a constant soippiSub would be the one to use if bothargumetns are images.

The problem is that the twos-complement method is actually a two-step process: 1st invert all bits, 2nd add one. So on each pixel the operation is more precisely: Out = (A+invert(B)+1)>>1. As you can see, the result in the parentheses actually requires 9 bits and therefore must be evaluated in a single function call. Splitting up the problem in several function calls will cost a bit (literarily ;) ). It might be that I am simply asking too much, but it would be a very nice function to have.

Or maybe the only solution is to convert to 16 bits (16u), make a left-shift, perform a subtraction, right-shift, and convert back to 8u. But is seems to be an awfully lot of memory allocation and operations to achieve a non-saturated subtraction of two 8u-images.

if there is a shorter way to the goal, please let me know.

Best regards, Peter
Reply