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.30943685, 0.07815447, 0.11052593, ..., 0.15770263,
0.27975454, 0.27801302],
[0.64003183, 0.44886105, 0.2904608 , ..., 0.23855426,
0.47992419, 0.34685259],
[0.38082354, 0.31888829, 0.37153553, ..., 0.0620955 ,
0.19704127, 0.14393142],
...,
[0.7440038 , 0.36217645, 0.20488977, ..., 0.15783049,
0.57166248, 0.40961413],
[0.4524933 , 0.14766652, 0.4091268 , ..., 0.40577065,
0.09215535, 0.47559542],
[0.32771118, 0.32969444, 0.40888935, ..., 0.17608976,
0.43442239, 0.45376096]],
[[0.34593295, 0.40225882, 0.46683162, ..., 0.45142655,
0.46006668, 0.35848168],
[0.29112813, 0.12742328, 0.14558683, ..., 0.18031951,
0.51472069, 0.31954731],
[0.44652347, 0.07575093, 0.60223508, ..., 0.54111725,
0.28873202, 0.45069324],
...,
[0.20598541, 0.22620001, 0.67758135, ..., 0.26585057,
0.37192383, 0.31210632],
[0.07680077, 0.13661258, 0.10296917, ..., 0.36755045,
0.47909886, 0.50641769],
[0.58795234, 0.37116267, 0.40526112, ..., 0.43557004,
0.2626804 , 0.4277083 ]],
[[0.3446302 , 0.51958671, 0.42264245, ..., 0.39087081,
0.26017878, 0.36350531],
[0.06884004, 0.42371568, 0.56395237, ..., 0.58112623,
0.00535511, 0.3336001 ],
[0.17265299, 0.60536078, 0.02622939, ..., 0.39678726,
0.51422671, 0.40537535],
...,
[0.05001079, 0.41162353, 0.11752888, ..., 0.57631894,
0.0564137 , 0.27827956],
[0.47070594, 0.7157209 , 0.48790402, ..., 0.2266789 ,
0.42874579, 0.01798689],
[0.08433648, 0.29914289, 0.18584953, ..., 0.3883402 ,
0.30289722, 0.11853074]]], 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))