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.open(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.30396568, 0.13290537, 0.25473741, ..., 0.38347368,
0.26859902, 0.2823776 ],
[0.06520485, 0.40579184, 0.37874635, ..., 0.61491236,
0.71422229, 0.41605045],
[0.1720361 , 0.31728443, 0.44709416, ..., 0.25668822,
0.34134474, 0.41054761],
...,
[0.39526989, 0.04415694, 0.14759223, ..., 0.36025458,
0.04254939, 0.5524101 ],
[0.08010561, 0.36124236, 0.37232136, ..., 0.68580596,
0.34808423, 0.04977589],
[0.39261828, 0.50539599, 0.34427547, ..., 0.02637387,
0.38971725, 0.41781918]],
[[0.34621649, 0.44341462, 0.14106843, ..., 0.39570078,
0.44625096, 0.37530011],
[0.04829844, 0.39487242, 0.27906451, ..., 0.26930893,
0.18557063, 0.49488955],
[0.13618174, 0.49658102, 0.10178491, ..., 0.25008261,
0.22365257, 0.08725587],
...,
[0.5100923 , 0.83043763, 0.78376005, ..., 0.28995439,
0.05493828, 0.27814628],
[0.27450107, 0.36210561, 0.31293681, ..., 0.00352617,
0.22926516, 0.60365781],
[0.36589989, 0.38307728, 0.23368543, ..., 0.91377574,
0.3367404 , 0.54015969]],
[[0.34981783, 0.42368001, 0.60419415, ..., 0.22082554,
0.28515002, 0.34232229],
[0.88649671, 0.19933573, 0.34218914, ..., 0.11577871,
0.10020708, 0.08906 ],
[0.69178215, 0.18613455, 0.45112092, ..., 0.49322917,
0.43500269, 0.50219652],
...,
[0.09463781, 0.12540543, 0.06864772, ..., 0.34979103,
0.90251233, 0.16944362],
[0.64539332, 0.27665203, 0.31474183, ..., 0.31066787,
0.42265061, 0.3465663 ],
[0.24148182, 0.11152673, 0.4220391 , ..., 0.0598504 ,
0.27354235, 0.04202112]]], 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:
fuse_dempster_shafer_2(*images) method of 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:
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))