import rastereasy

Dempster-Shafer fusion for 2 hypotheses

It is possible to fuse belief masses issued from images for two hypotheses A and B. For this, we assume that each image is composed of 3 spectral bands :

  • 1st band : belief mass $m(A)$ for hypothesis $A$

  • 2nd band : belief mass $m(B)$ for hypothesis $B$

  • 3rd band : belief mass $m(A \cup B)$ for hypothesis $A \cup B$ (uncertainty)

For consistent mass functions, the sum along bands must be $1$ for each pixel of each source

1) Create 5 toy images

# 1. Read image (just to have meta informations)
name_im='./data/demo/sentinel.tif'
image=rastereasy.Geoimage(name_im)
# 2. Create a 3 band image consistent with mass functions (i.e. positive and  sum to 1)
import numpy as np
raw = np.random.rand(image.shape[0], image.shape[1], 3)
# 3. Normalize  mass functions such that m(A) + m(B) + m(A∪B) = 1 in each pixel
mass_functions = raw / np.sum(raw, axis=2, keepdims=True)
print(mass_functions.shape)
# 4. Upload the table 
mass_function1 = image.upload_image(mass_functions,channel_first=False)
# 5 verify that the sum is 1 along bands
print(mass_function1.sum(axis='band'))

## Repeat this operation 5 times to create 5 sources
raw = np.random.rand(image.shape[0], image.shape[1], 3)
mass_functions = raw / np.sum(raw, axis=2, keepdims=True)
mass_function2 = image.upload_image(mass_functions,channel_first=False)

raw = np.random.rand(image.shape[0], image.shape[1], 3)
mass_functions = raw / np.sum(raw, axis=2, keepdims=True)
mass_function3 = image.upload_image(mass_functions,channel_first=False)

raw = np.random.rand(image.shape[0], image.shape[1], 3)
mass_functions = raw / np.sum(raw, axis=2, keepdims=True)
mass_function4 = image.upload_image(mass_functions,channel_first=False)

raw = np.random.rand(image.shape[0], image.shape[1], 3)
mass_functions = raw / np.sum(raw, axis=2, keepdims=True)
mass_function5 = image.upload_image(mass_functions,channel_first=False)
(1000, 1000, 3)
[[1. 1. 1. ... 1. 1. 1.]
 [1. 1. 1. ... 1. 1. 1.]
 [1. 1. 1. ... 1. 1. 1.]
 ...
 [1. 1. 1. ... 1. 1. 1.]
 [1. 1. 1. ... 1. 1. 1.]
 [1. 1. 1. ... 1. 1. 1.]]
mass_function1.image
array([[[0.12571802, 0.25086056, 0.18328983, ..., 0.09160784,
         0.16420958, 0.22534334],
        [0.22449783, 0.05369949, 0.13427468, ..., 0.48883442,
         0.55197949, 0.61125815],
        [0.41689285, 0.04157854, 0.50268653, ..., 0.07765427,
         0.41123555, 0.33504538],
        ...,
        [0.05546719, 0.75829898, 0.50423343, ..., 0.38172759,
         0.25669968, 0.37609214],
        [0.64042402, 0.29924155, 0.1708952 , ..., 0.2388334 ,
         0.48679624, 0.20806528],
        [0.23922514, 0.53796906, 0.44941302, ..., 0.35755458,
         0.25504246, 0.446345  ]],

       [[0.4546271 , 0.10578535, 0.49255176, ..., 0.472167  ,
         0.59570854, 0.38831502],
        [0.27936   , 0.69792962, 0.194582  , ..., 0.18611645,
         0.36901982, 0.23794597],
        [0.27687108, 0.46032741, 0.0916974 , ..., 0.60872449,
         0.07072767, 0.32069137],
        ...,
        [0.44288423, 0.12847884, 0.15907349, ..., 0.12155445,
         0.46674052, 0.56966528],
        [0.34087475, 0.69525966, 0.70591245, ..., 0.30560047,
         0.32621901, 0.73158923],
        [0.71419186, 0.05437057, 0.1414912 , ..., 0.61960515,
         0.35577265, 0.40328638]],

       [[0.41965488, 0.64335409, 0.32415841, ..., 0.43622516,
         0.24008188, 0.38634163],
        [0.49614217, 0.24837089, 0.67114331, ..., 0.32504913,
         0.07900069, 0.15079588],
        [0.30623606, 0.49809405, 0.40561608, ..., 0.31362124,
         0.51803679, 0.34426325],
        ...,
        [0.50164858, 0.11322218, 0.33669308, ..., 0.49671796,
         0.27655981, 0.05424259],
        [0.01870123, 0.00549879, 0.12319235, ..., 0.45556613,
         0.18698475, 0.06034549],
        [0.046583  , 0.40766037, 0.40909578, ..., 0.02284027,
         0.38918489, 0.15036862]]], shape=(3, 1000, 1000))

2) Perform the fusion

1) With function fuse_dempster_shafer_2 of class Geoimage

help(mass_function1.fuse_dempster_shafer_2)
Help on method fuse_dempster_shafer_2 in module rastereasy.rastereasy:

fuse_dempster_shafer_2(*images) method of rastereasy.rastereasy.Geoimage instance
    Fuse the 3 band image (associated with mass functions) from multiple
    sources using Dempster-Shafer theory with two hypotheses: A and B.
    
    Parameters
    ----------
    *images : Geoimage
        Each input is a 3-band Geoimage.
    
        - Band 1: mass function m(A)
    
        - Band 2: mass function m(B)
    
        - Band 3: mass function m(A ∪ B)
    
    Returns
    -------
    Geoimage
        A new Geoimage with 3 bands containing the fused mass functions:
        m(A), m(B), and m(A ∪ B).
    Geoimage
        A new Geoimage with 1 band containing the conflict values.
    
    Examples
    --------
    >>> fused, conflict = im1.fuse_dempster_shafer_2(im2)
    >>> fused, conflict = im1.fuse_dempster_shafer_2(im1, im2, im3, im4)
fusion, conflict = mass_function2.fuse_dempster_shafer_2(mass_function5,mass_function4,mass_function1,mass_function3)

2) With function fuse_dempster_shafer_2hypotheses of class InferenceTools

help(rastereasy.InferenceTools.fuse_dempster_shafer_2hypotheses)
Help on function fuse_dempster_shafer_2hypotheses in module rastereasy.rastereasy:

fuse_dempster_shafer_2hypotheses(*images)
    Fuse mass functions from multiple sources using Dempster-Shafer theory
    with two hypotheses: A and B.
    
    Parameters
    ----------
    *images : Geoimage
        Each input is a 3-band Geoimage.
    
        - Band 1: mass function m(A)
    
        - Band 2: mass function m(B)
    
        - Band 3: mass function m(A ∪ B)
    
    Returns
    -------
    Geoimage
        A new Geoimage with 3 bands containing the fused mass functions:
        m(A), m(B), and m(A ∪ B).
    Geoimage
        A new Geoimage with 1 band containing the conflict values.
    
    Examples
    --------
    >>> fused, conflict = fuse_dempster_shafer_2hypotheses(im1, im2, im3)
    >>> fused, conflict = fuse_dempster_shafer_2hypotheses(im1, im2, im3, im4)
    >>> fused, conflict = fuse_dempster_shafer_2hypotheses(im1, im2)
fusion, conflict = rastereasy.InferenceTools.fuse_dempster_shafer_2hypotheses(
    mass_function5,
    mass_function4,
    mass_function3,
    mass_function2,
    mass_function1)

Verify that the fused masses sum to $1$

fusion.sum(axis='band')
array([[1., 1., 1., ..., 1., 1., 1.],
       [1., 1., 1., ..., 1., 1., 1.],
       [1., 1., 1., ..., 1., 1., 1.],
       ...,
       [1., 1., 1., ..., 1., 1., 1.],
       [1., 1., 1., ..., 1., 1., 1.],
       [1., 1., 1., ..., 1., 1., 1.]], shape=(1000, 1000))