Android Can i use setTo() with a Condition, just like in C/C++

asked 2014-04-16 14:06:54 -0600

DHeil86 gravatar image

updated 2014-04-16 14:09:52 -0600


i am actually porting some code to Android, but i don't know, how i can translate this code :

myMat.setTo(0, otherMat < threshVal);

As i think, every value in the matrix - myMat is set to 0 when the value at the corresponding place in "otherMat" is lower than "threshVal" - right?

I would just use a for-loop to solve this, but i think there must be a better way - just as in the C-Code Version.

Also - how to translate this C-Code:

myMat = myMat / ( otherMat+1 );

Thank you for your help.

edit retag flag offensive close merge delete



in any case, avoid for-loops(over the pixels) in java

berak gravatar imageberak ( 2014-04-16 14:11:46 -0600 )edit

i guess, that threshold does not work for me - all the threshold-types are checking for - src(x,y) > thresh - but i need - if (src(x,y) < thresh) then 0 otherwise dst(x,y).

or am i wrong?

DHeil86 gravatar imageDHeil86 ( 2014-04-16 15:07:27 -0600 )edit

it has a flag to invert it

berak gravatar imageberak ( 2014-04-16 15:15:07 -0600 )edit

so i now have:

Imgproc.threshold(otherMat, myMat, threshVal, 0, Imgproc.THRESH_TOZERO_INV);

where do i find that inverting-flag? or where do i put it in?

another question is that i ONLY want to set the value to 0 if the condition is fulfilled and leave the value alone when not - because that is, what the C-Code says , right?

DHeil86 gravatar imageDHeil86 ( 2014-04-16 15:25:06 -0600 )edit

"i ONLY want to set the value to 0 if the condition is fulfilled and leave the value alone when not" -

i already feared you would say this. yes alright a plain threshold does not do this exactly.

you probbaly generate a binary mask (using threshold) in this case, and supply it as additional input to to binary_and() or binary_or()

yea, damn, the java api does not know nifty operator overloading, you have to get creative here ..

berak gravatar imageberak ( 2014-04-16 15:32:42 -0600 )edit

alright - thats what i thought... :/

thank you for your help.

or maybe i am totally wrong - what exactly does " myMat.setTo(0, otherMat < threshVal); " do?

DHeil86 gravatar imageDHeil86 ( 2014-04-16 15:51:34 -0600 )edit