bpdl.pattern_weights module

Estimating pattern weight vector for each image

Copyright (C) 2015-2020 Jiri Borovec <jiri.borovec@fel.cvut.cz>

bpdl.pattern_weights.convert_weights_binary2indexes(weights)[source]

convert binary matrix oof weights to list of indexes o activated ptns

Parameters

weights (ndarray) – np.array<nb_imgs, nb_lbs>

Return list(list(int))

>>> weights = np.array([[ 0,  0,  1,  0],
...                     [ 0,  0,  0,  1],
...                     [ 1,  0,  0,  0],
...                     [ 0,  0,  1,  1],
...                     [ 1,  0,  0,  0]])
>>> convert_weights_binary2indexes(weights)
[array([2]), array([3]), array([0]), array([2, 3]), array([0])]
bpdl.pattern_weights.initialise_weights_random(nb_imgs, nb_patterns, ratio_select=0.2, rand_seed=None)[source]
Parameters
  • nb_imgs (int) – number of all images

  • nb_patterns (int) – number of all available labels

  • ratio_select (float) – number <0, 1> defining how many should be set on, 1 means all and 0 means none

  • rand_seed – random initialization

Return ndarray

np.array<nb_imgs, nb_labels>

>>> initialise_weights_random(5, 3, rand_seed=0)
array([[ 0.,  0.,  1.,  0.],
       [ 0.,  0.,  0.,  1.],
       [ 1.,  0.,  0.,  0.],
       [ 0.,  0.,  1.,  1.],
       [ 1.,  0.,  0.,  0.]])
bpdl.pattern_weights.weights_image_atlas_overlap_major(img, atlas)[source]
Parameters
  • img (ndarray) – image np.array<height, width>

  • atlas (ndarray) – image np.array<height, width>

Return list(int)

list(int) * nb_lbs of values {0, 1}

>>> atlas = np.zeros((8, 10), dtype=int)
>>> atlas[:3, 0:4] = 1
>>> atlas[3:7, 5:10] = 2
>>> img = np.array([0, 1, 0])[atlas]
>>> weights_image_atlas_overlap_major(img, atlas)
[1, 0]
>>> img = [[0.46, 0.62, 0.62, 0.46, 0.2,  0.04, 0.01, 0.0,  0.0,  0.0],
...        [0.44, 0.59, 0.59, 0.44, 0.2,  0.06, 0.04, 0.04, 0.04, 0.04],
...        [0.33, 0.44, 0.44, 0.34, 0.2,  0.17, 0.19, 0.2,  0.2,  0.2],
...        [0.14, 0.19, 0.19, 0.17, 0.2,  0.34, 0.44, 0.46, 0.47, 0.47],
...        [0.03, 0.04, 0.04, 0.06, 0.2,  0.44, 0.59, 0.62, 0.62, 0.62],
...        [0.0,  0.0,  0.01, 0.04, 0.19, 0.44, 0.59, 0.62, 0.62, 0.62],
...        [0.0,  0.0,  0.0,  0.03, 0.14, 0.33, 0.44, 0.46, 0.47, 0.47],
...        [0.0,  0.0,  0.0,  0.01, 0.06, 0.14, 0.19, 0.2,  0.2,  0.2]]
>>> weights_image_atlas_overlap_major(np.array(img), atlas)
[0, 1]
bpdl.pattern_weights.weights_image_atlas_overlap_partial(img, atlas)[source]
Parameters
  • img (ndarray) – image np.array<height, width>

  • atlas (ndarray) – image np.array<height, width>

Return list(int)

list(int) * nb_lbs of values {0, 1}

>>> atlas = np.zeros((8, 10), dtype=int)
>>> atlas[:3, 0:4] = 1
>>> atlas[3:7, 5:10] = 2
>>> img = np.array([0, 1, 0])[atlas]
>>> weights_image_atlas_overlap_partial(img, atlas)
[1, 0]
>>> img = [[0.46, 0.62, 0.62, 0.46, 0.2,  0.04, 0.01, 0.0,  0.0,  0.0],
...        [0.44, 0.59, 0.59, 0.44, 0.2,  0.06, 0.04, 0.04, 0.04, 0.04],
...        [0.33, 0.44, 0.44, 0.34, 0.2,  0.17, 0.19, 0.2,  0.2,  0.2],
...        [0.14, 0.19, 0.19, 0.17, 0.2,  0.34, 0.44, 0.46, 0.47, 0.47],
...        [0.03, 0.04, 0.04, 0.06, 0.2,  0.44, 0.59, 0.62, 0.62, 0.62],
...        [0.0,  0.0,  0.01, 0.04, 0.19, 0.44, 0.59, 0.62, 0.62, 0.62],
...        [0.0,  0.0,  0.0,  0.03, 0.14, 0.33, 0.44, 0.46, 0.47, 0.47],
...        [0.0,  0.0,  0.0,  0.01, 0.06, 0.14, 0.19, 0.2,  0.2,  0.2]]
>>> weights_image_atlas_overlap_partial(np.array(img), atlas)
[1, 1]
bpdl.pattern_weights.weights_image_atlas_overlap_threshold(img, atlas, threshold=1.0)[source]

estimate what patterns are activated with given atlas and input image compute overlap matrix and eval nr of overlapping and non pixels and threshold

Parameters
  • img (ndarray) – image np.array<height, width>

  • atlas (ndarray) – image np.array<height, width>

  • threshold (float) – represent the ration between overlapping and non pixels

Return list(int)

list(int) * nb_lbs of values {0, 1}

bpdl.pattern_weights.weights_label_atlas_overlap_threshold(imgs, atlas, label, threshold=1.0)[source]

estimate what patterns are activated with given atlas and input image compute overlap matrix and eval nr of overlapping and non pixels and threshold

Parameters
  • imgs (list(ndarray)) – list of images np.array<height, width>

  • atlas (ndarray) – image np.array<height, width>

  • label (int) –

  • threshold (float) – represent the ration between overlapping and non pixels

Return ndarray

np.array<nb_imgs> of values {0, 1}

>>> atlas = np.zeros((8, 12), dtype=int)
>>> atlas[:3, 1:5] = 1
>>> atlas[3:7, 6:12] = 2
>>> luts = np.array([[0, 1, 0]] * 3 + [[0, 0, 1]] * 3 + [[0, 1, 1]] * 3)
>>> imgs = [lut[atlas] for lut in luts]
>>> atlas[atlas == 2] = 0
>>> weights_label_atlas_overlap_threshold(imgs, atlas, 2)
array([0, 0, 0, 0, 0, 0, 0, 0, 0])