Multivariate Alteration Detection use on different images

Dear all,

do you think there is a way to save the transformation used in MAD to use in different images?

For instance I made a MAD transformation between images 2015 and 2017, used supervised classfication to distinguish different classes of change. Can I use the same MAD equation on image from 2018 (compared to 2015) to use the same classification model?

Thanks for help!
Robert

Hello,

You can’t do that directly with the MAD application.

Maybe you could use the BandMathX application to apply the transformation:

otbcli_BandMathX -il image1.tif image2.tif -out /tmp/out2.tif -incontext context.txt  -exp "(im1-m1)*v1 - (im2-m2)*v2"

with context.txt :

#M v1 {0.0219272, 0.00167021, -0.00430969, 0.000601005; -0.0147543, 0.0146592, 0.00119559, -0.000513982; -0.000439127, -0.0095992, 0.00404977, 0.00104122 ; 0.00113085, -0.00129218, 0.000491191, -0.000723041} 
#M v2 {0.0206995, -0.0003979, -0.00565285, 0.000891043; -0.0156111, 0.0169544, 0.00101618, -0.001636; 0.000689719, -0.00998213, 0.00544778, 0.00182974; 0.00127694, -0.0016468, 0.000519441, -0.000763441}
#M m1 {442.212, 701.321, 677.34, 3039.14}
#M m2 {463.749, 689.889, 677.502, 2750.86} 

containing the MAD transformation matrices (v1, v2) and the mean vectors (m1, m2).
The values are given as logs by the application.

Cédric

1 Like

Thanks for your help! It looks like it gonna work!

Are you sure about the expression “(im1-m1)*v1”? Shouldn’t be (im-m1) mult v1, since it is not scalar?

Using your content.txt I got an error, that “following variables not allowed: m1, m2, v1, v2.” I put the vectors straight into the expression and it works

If you are using OTB 6.6.1 or below, you should put the expression in the context file :

#M v1 {0.0219272, 0.00167021, -0.00430969, 0.000601005; -0.0147543, 0.0146592, 0.00119559, -0.000513982; -0.000439127, -0.0095992, 0.00404977, 0.00104122 ; 0.00113085, -0.00129218, 0.000491191, -0.000723041}
#M v2 {0.0206995, -0.0003979, -0.00565285, 0.000891043; -0.0156111, 0.0169544, 0.00101618, -0.001636; 0.000689719, -0.00998213, 0.00544778, 0.00182974; 0.00127694, -0.0016468, 0.000519441, -0.000763441}
#M m1 {442.212, 701.321, 677.34, 3039.14}
#M m2 {463.749, 689.889, 677.502, 2750.86}
#E (im1-m1)*v1 - (im2-m2)*v2

In OTB 7.0 you can define variables in the context file and use them in the “exp” parameter.

I think * should be used, it is the usual matrix/vector product. mult is the element wise product.

Maybe the best way to check if it works is to use BandMathX with your original images of 2015 and 2017 and compare with the result obtained with the MAD application.

Cédric

Thanks for your help! I started as you said by comparing MAD with BandMathX starting from 1-band image:

(im1-m1)*v1 - (im2-m2)*v2 - this expression worked perfect

For 2-band image I tried:

(im1-m1)v1 - (im2-m2)v2 and I got message:
Message: Matrix dimension error.
Formula: cat((im1-{2.03386, 2.03949})
{4.09639, 0.960741,-3.82533, 1.43746} - (im2- {2.04743, 2.04657})
{4.09639, 0.960741,-3.82533, 1.43746})
Token: *
Position: 28

In my formula i have semi-colon, but in log i have comma , between rows.

I tried also
(im1-m1) mult v1 - (im2-m2) mult v2
((im1-m1) mult v1) - ((im2-m2) mult v2)
Also with transposed matrixes v1 and v2, but all images led to wrong image.

Do you see any solution?

Can you try with the expression in the context file like I described in my previous answer ?

I think there is a problem with matrix definition inside the expression, because the ; operator has another meaning for the application : concatenation, the expression

-exp "exp1 ; exp2" 

will concatenate the results of exp1 and exp2 in the output image. This can be useful, but this means that matrices cannot be defined on the fly… This is a bug and I opened an issue on otb Gitlab ( https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb/issues/1975).

Anyway, in your case it should work with the context file.

Cédric

Ok, I get it why it doesn’t work on fly!

But it still doesn’t work with content file. Without putting expression I get "Following variables not allowed : m1 m2 v1 v2 "

If I put expression in the context file I don’t know what to put after -exp since it is a mandatory field. Both empty “” {} don’t work. As well as naming expression in context file and puting it as a variable?

How are you using otb ? (CommandLine, Python, monteverdi, … ?). Also you are using otb 6.6.1 right ?

exp is a mandatory file, but if an expression is detected in the context file, the exp parameter should be set automatically by the application (internally). So the command line otbcli_BandMathX -incontext context.txt -il im1.tif im2.tif -out out.tif should work.

Cedric, unfortunately it doesn’t work in terminal as well as in Mapla:

MacBook-Pro-muphygen:bin muphygen$ ./otbcli_BandMathX -il ./obrazy/MAD_2band_input1.tif ./obrazy/MAD_2band_input2.tif -incontext ./obrazy/MAD2.txt -out ./obrazy/MAD2_proba.tif

ERROR: Missing mandatory parameter -exp.

MAD2.txt:

#M v1 {4.09639, 0.960741;
-3.82533, 1.43746}

#M v2 {-4.21497, 1.1905;
4.29302, 0.999779}

#M m1 {2.03386, 2.03949}

#M m2 {2.04743, 2.04657}

#E (im1-m1)*v1 - (im2-m2)*v2

It looks like a bug?

Thanks for your patience!

I think the problem is that your matrices are defined on several lines, but the application parses the file line by line.

It should be :

#M v1 {4.09639, 0.960741; -3.82533, 1.43746}

#M v2 {-4.21497, 1.1905; 4.29302, 0.999779}

#M m1 {2.03386, 2.03949}

#M m2 {2.04743, 2.04657}

#E (im1-m1)*v1 - (im2-m2)*v2

Tell me if it works,
Cédric

Thanks, I’ve done it, but anyway I couldn’t skip this problem.