How to calculate the Bhattacharyya distance/index?

4 messages Options
Embed this post
Permalink
Nikos Alexandris

How to calculate the Bhattacharyya distance/index?

Reply Threaded More More options
Print post
Permalink
I need to calculate the Bhattacharyya distance (or better said the
Bhatt. separability index) for unburned and burned area samples
extracted from both prefire and postfire MODIS surface reflectance
products.

I haven't found any foss "tool" that will do this for me. So I am trying
to code it in R.

#==================================================
# Calculate bhattacharayya distance in R

# define new function
dBh <- function(PRE, POST){

        # column-wise mean and cov for PRE
        m.pre <- colMeans(PRE)
        c.pre <- cov(PRE)

        # column-wise mean and cov for POST
        m.post <- colMeans(POST)
        c.post <- cov(POST)

        # mean difference and its transpose matrix
        m.diff <- as.matrix(m.pre - m.post)
                m.diff.t <- t(m.diff)

        # halfsum of covariances
        C <- (c.pre + c.post)/2

# the index
index <- 0.125 * m.diff.t %*% C %*% m.diff + 0.5 *
log10( det(C)/sqrt( det(c.pre)*det(c.post)))

# print result
index
}
#===================================================

I am trying to use the code on two matrices with the following
structure:

# rows are the total number of pixels sampled
# columns correspond to MODIS bands 1, 2, 5, 6 and 7
> str(pre.bs6)

 int [1:371, 1:5] 986 986 1086 1094 1094 1217 1217 1258 1391 1475 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:5] "prefire.band1" "prefire.band2" "prefire.band5"
"prefire.band6" ...


> str(post.bs6)

 int [1:371, 1:5] 1007 1175 1007 1039 1146 1077 1078 1280 1249 1218 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:5] "postfire.band1" "postfire.band2" "postfire.band5"
"postfire.band6" ...


My problem is that (a) I have coded it falsely  or  (b) I don't
understand "how to use the result given that the above instructions are
correct. The result is *too* big, thus it will probably ground the
Bhattacharayya coefficient to 0.

I expect that prefire samples against postfire samples [ given the very
good (or good) discrimination ability of those two "classes" in MODIS
bands 2, 5, (6 and 7) ] will return some "great" Bhattacharayya
coefficient. Or am I wrong?

Any instructions on how to get it done?
Thanks, Nikos

---
[1] http://en.wikipedia.org/wiki/Bhattacharyya_coefficient
[2] http://en.wikipedia.org/wiki/Bhattacharya_coefficient

_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats
Agustin Lobo-2

Re: How to calculate the Bhattacharyya distance/index?

Reply Threaded More More options
Print post
Permalink
JM is bounded between 0 and 2.
An example here:
http://wija.ija.csic.es/gt/obster/ABSTRACTS/aloboIJRS2004.pdf

Agus


Nikos Alexandris wrote:

> [...]
>
> Agus,
>
> thank you very much. Your code was very useful for me to understand a
> mistake in "my" code [1] and (perhaps) use the "JM" [2] distance instead
> of the Bhattacharayya (?). I am unsure.
>
> Thanks, Nikos
>
>
> [1] correct: "solve( ( covariance.1 + covariance.2 ) / 2 )",
>     wrong: ( ( covariance.1 + covariance.2 ) / 2 )
>
>

--
Dr. Agustin Lobo
Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
LLuis Sole Sabaris s/n
08028 Barcelona
Spain
Tel. 34 934095410
Fax. 34 934110012
email: [hidden email]
http://www.ija.csic.es/gt/obster
_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats
Nikos Alexandris

Re: How to calculate the Bhattacharyya distance/index?

Reply Threaded More More options
Print post
Permalink
Agus,

I really appreciate your kind support. It's important to have some hand
to push you a bit when you are stuck :-) I am convinced that you know
that better than many other people.

The problem is that I must use it wrong. I have 42 samples (number of
pixel varies and is not really too big) extracted from:

(1) a 3x3 matrix with columns MODIS prefire.band2, prefire.band 6 and
prefire.band7

(2) a 3x3 matrix with columns MODIS postfire.band2, postfire.band 6 and
postfire.band 7

When I feed these two as PRE and POST in my function JM <-
function(PRE,POST) etc., I get a Bhattacharayya distance of -50.xxx and
the JM becomes something like -7.xxx

As you might have noticed I use colMeans() to calculate each bands mean.
I really am stuck and can't seem to understand what I am doing wrong. Is
it really that difficult? :-0

Thank you in advance, of course even if you don't have the time to
reply. Nikos

_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats
Nikos Alexandris

Re: How to calculate the Bhattacharyya distance/index?

Reply Threaded More More options
Print post
Permalink
On Sat, 2009-02-14 at 14:27 +0100, Nikos Alexandris wrote:
[...]
> I have 42 samples (number of
> pixel varies and is not really too big) extracted from:
>
> (1) a 3x3 matrix with columns MODIS prefire.band2, prefire.band 6 and
> prefire.band7
>
> (2) a 3x3 matrix with columns MODIS postfire.band2, postfire.band 6
> and
> postfire.band 7
[...]

Sorry, the above is unclear!

I have 42 vector *boxes* (not all of them are rectangulars, manually
digitised samples) which I used to extract pixels from MODIS, prefire
and postfire (bands 2, 6 and 7 respectively).

I hat put the prefire samples in a matrix "xxx rows by 3 columns" and
the same for the postfire samples. Then I try to run the function.

I see that my mistake is that I put them all-together!? I should compare
them band-wise probably.

Nikos

_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats