Solved

# what exactly these functions do to narrow matrix ranges

Posted on 2007-07-30
Medium Priority
443 Views
If anyone can help me understand what this function does, I would appreciate it:

cvAbsDiffS(Image1, Image2, s);

What is the functions doing to the array? How does it use "s"  scalar value to do that? Finally, this function and cvSubS have been suggested to select out pixel hue ranges to isolate color in HSV space. I understand HSV space, just not what these functions are doing to the arrays passed through them.

AbsDiffS

Calculates absolute difference between array and scalar

void cvAbsDiffS( const CvArr* A, CvArr* C, CvScalar S );
#define cvAbs(A, C) cvAbsDiffS(A, C, cvScalarAll(0))

A
The source array.
C
The destination array.
S
The scalar.

The function cvAbsDiffS calculates absolute difference between array and scalar.

C(I)c = abs(A(I)c - Sc).

All the arrays must have the same data type and the same size (or ROI size).

------------------

SubS

Computes difference of array and scalar

void cvSubS( const CvArr* A, CvScalar S, CvArr* C, const CvArr* mask=0 );

A
The source array.
S
Subed scalar.
C
The destination array.
Operation mask, 8-bit single channel array; specifies elements of destination array to be changed.

The function cvSubS subtracts a scalar from every element of the source array:

All the arrays must have the same type, except the mask, and the same size (or ROI size)

----------------------------------------

If I understood what calculations were being employed, I could pick the correct S scalar value to choose a hue range.

Help...

WLE
0
Question by:Wanderinglazyeye
• 6
• 4

LVL 86

Expert Comment

ID: 19593112
As they state: C(I)c = abs(A(I)c - Sc)

That means that each elemnt of the destination array is created by subtracting the scalar from the corresponding element (cotrresponding by index) in the source array. The same applies to the other function usind addition instead and a mask value.
0

LVL 46

Assisted Solution

Kent Olsen earned 400 total points
ID: 19593142
Hi WLE,

cvAbsDiffS () returns an array that is a comparison of the pixels in the first array with a scalar value.  The second array can then be scanned to easily find pixels that are within a couple of 'hues' of the original color.

cvSubS () does the same thing, but it returns a signed value.  The second array can then be scanned to easily find pixels that have "at least" a specific hue.

Good Luck,
Kent
0

Author Comment

ID: 19593701
Hi Kent & JKR,

If I want to find all pixels in the Hue range of 110-118, for example, what would be my scalar value then for the absdiffs?
0

LVL 86

Expert Comment

ID: 19593755
I think there is a misconception about what to use these functions for. The result is always a vector, so you could just change your test criteria, i.e. subtracr 110 and check for values > 0 etc. Since you still have to loop through the vector result, it you as well use a loop to test the values for the range [110;118] without subtracting anything first.
0

LVL 86

Expert Comment

ID: 19593780
Hm, maybe 'cvLUT()' would better match your needs, i.e. if you provide a lookjup tabe that has only '0' for values other than [110;118] and the values within the range for the others. The result will have '0' for all pixels except the ones within [110;118].
0

Author Comment

ID: 19594356
Go to your post, 2 above. If I subtract 110 from each array element, what is being subtracted from what? I need to visualize what is occuring. Is it turning off pixels not in the range? Also, how would we write this?

CvScalar s = CvScalar (110,118);
CvAbsDiffs(Image1, Image2, s);

Might this be how?

As for the LUT, I want to avoid iterating for the moment, it consumes time. I beleive the native cxcore matrix functions are faster.

Thanks WLE

0

LVL 86

Expert Comment

ID: 19594420
>>f I subtract 110 from each array element, what is being subtracted from what?

110 is being subtracted from each pixel value - I am not sure where you would benefit from that.

>>As for the LUT, I want to avoid iterating for the moment

Um, that is a single function call, there is no iteration. -The idea was to zero-out all pixels that do not fall in the range of [110;118].
0

Author Comment

ID: 19596800
I think you my be correct JKR. But would I have to call the function eight times in a loop changing the lookup value 8 times for the range 110-118?
0

LVL 86

Accepted Solution

jkr earned 1600 total points
ID: 19597159
Nooo, not at all - you would provide a lookup table where only the entries for 110-118 contain the values 110-118, everything else set to null. This will effectively filter all values not in that range on a single call.
0

Author Comment

ID: 19597179
So I must make a lookup table...this I will try.
0

LVL 86

Expert Comment

ID: 19597192
A pretty simple one, actually ;o)
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct ā¦
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a ā¦
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
###### Suggested Courses
Course of the Month13 days, 22 hours left to enroll