Can somebody explain to me what 'void postConcat' in Android does?

203 views Asked by At

So I have 2 matrices.

Colormatrix and Threshold. Colormatrix is initially,

C =  [  0.213 0.715 0.072 0 0;
        0.213 0.715 0.072 0 0;
        0.213 0.715 0.072 0 0;
           0    0     0   1 0;]

and threshold is:

T = [   255 0 0 1 -306;
        0 255 0 1 -306;
        0 0 255 1 -306;
        0 0  0  1 -306;]

Now this line of code in android colorMatrix.postConcat(threshold); returns this:

C =  [  54.315 182.325 18.36 1 -306;
        54.315 182.325 18.36 1 -306;
        54.315 182.325 18.36 1 -306;
           0      0      0   1   0; ]

Why? What are the steps that it follows to come to that result?

If I do the same thing in Matlab, that is C*T' I get this:

C =  [  54.315 182.325 18.36 0;
        54.315 182.325 18.36 0;
        54.315 182.325 18.36 0;
           0      0      0   0; ]

A different dimension array with different values. Can somebody explain to me what postConCat does? I can't find anything online about this function, only in the Android documentation, and it says only this:

Concat this colormatrix with the specified postmatrix. 

. Is it only an Android thing?

1

There are 1 answers

0
Joe On BEST ANSWER

Why? What are the steps that it follows to come to that result?

The source code for ColorMatrix can be viewed here: https://android.googlesource.com/platform/frameworks/base/+/master/graphics/java/android/graphics/ColorMatrix.java

Is it only an Android thing?

I believe it kinda is, more like only a ColorMatrix thing. In Android, I believe ColorMatrix is only provided as a way to construct a special ColorFilter (ColorMatrixColorFilter) which is used mainly to be applied to Bitmap objects.

From the ColorMatrix.postConcat description:

This is logically the same as calling setConcat(postmatrix, this)

And from the description for setConcat:

Set this colormatrix to the concatenation of the two specified colormatrices, such that the resulting colormatrix has the same effect as applying matB and then applying matA.

So, if understand it correctly, I believe ColorMatrix.postConcat can be used to combine two ColorMatrix objects into one so you can then just apply it once to the Bitmap of your choice instead of doing it twice.

In short, if you want to have the same behavior with what you get in Matlab, you might need to implement it yourself.