You are provided with the RGBRGB values for a downsampled image and the downsampling coefficient (NN). Given the size of the original image (and assuming that the algorithm used for downsampling is the one described above), restore the original image using the interpolation or upsampling algorithm of your choice.


In [1]:
# #Python Library Imports
import numpy as np
import scipy.ndimage

In [3]:
x = np.arange(9).reshape(3,3)
x


Out[3]:
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])

In [8]:
data = np.arange(27).reshape(3,3,3)
data


Out[8]:
array([[[ 0,  1,  2],
        [ 3,  4,  5],
        [ 6,  7,  8]],

       [[ 9, 10, 11],
        [12, 13, 14],
        [15, 16, 17]],

       [[18, 19, 20],
        [21, 22, 23],
        [24, 25, 26]]])

In [10]:
scipy.ndimage.zoom(data, (1, 2, 2))


Out[10]:
array([[[ 0,  0,  1,  1,  2,  2],
        [ 1,  1,  1,  2,  2,  3],
        [ 2,  2,  3,  3,  4,  4],
        [ 4,  4,  5,  5,  6,  6],
        [ 5,  6,  6,  7,  7,  7],
        [ 6,  6,  7,  7,  8,  8]],

       [[ 9,  9, 10, 10, 11, 11],
        [10, 10, 10, 11, 11, 12],
        [11, 11, 12, 12, 13, 13],
        [13, 13, 14, 14, 15, 15],
        [14, 15, 15, 16, 16, 16],
        [15, 15, 16, 16, 17, 17]],

       [[18, 18, 19, 19, 20, 20],
        [19, 19, 19, 20, 20, 21],
        [20, 20, 21, 21, 22, 22],
        [22, 22, 23, 23, 24, 24],
        [23, 24, 24, 25, 25, 25],
        [24, 24, 25, 25, 26, 26]]])

In [ ]:


In [ ]:


In [ ]:


In [15]:
a = """0,0,200 0,0,10 10,0,0 90,90,50 90,90,10 255,255,255 100,100,88 80,80,80 15,75,255"""

In [16]:
a


Out[16]:
'0,0,200 0,0,10 10,0,0 90,90,50 90,90,10 255,255,255 100,100,88 80,80,80 15,75,255'

In [25]:
[map(int, i.split(",")) for i in a.split(" ")]


Out[25]:
[[0, 0, 200],
 [0, 0, 10],
 [10, 0, 0],
 [90, 90, 50],
 [90, 90, 10],
 [255, 255, 255],
 [100, 100, 88],
 [80, 80, 80],
 [15, 75, 255]]

In [26]:
np.array([map(int, i.split(",")) for i in a.split(" ")])


Out[26]:
array([[  0,   0, 200],
       [  0,   0,  10],
       [ 10,   0,   0],
       [ 90,  90,  50],
       [ 90,  90,  10],
       [255, 255, 255],
       [100, 100,  88],
       [ 80,  80,  80],
       [ 15,  75, 255]])

In [38]:
data_one = np.array([map(int, i.split(",")) for i in a.split(" ")]).reshape(3,3,3)
data_one


Out[38]:
array([[[  0,   0, 200],
        [  0,   0,  10],
        [ 10,   0,   0]],

       [[ 90,  90,  50],
        [ 90,  90,  10],
        [255, 255, 255]],

       [[100, 100,  88],
        [ 80,  80,  80],
        [ 15,  75, 255]]])

In [42]:
scipy.ndimage.zoom(data_one, 2, order=2)


Out[42]:
array([[[  0, -11, -19,  35, 147, 200],
        [ -1,  -8, -14,  26, 110, 150],
        [ -1,  -3,  -4,   8,  32,  44],
        [  2,   2,   1,  -2,  -7,  -9],
        [  7,   6,   2,  -2,  -6,  -7],
        [ 10,   7,   2,  -1,  -1,   0]],

       [[ 23,  16,  11,  47, 122, 158],
        [ 20,  16,  12,  37,  89, 114],
        [ 18,  18,  19,  21,  25,  27],
        [ 36,  37,  37,  28,  11,   3],
        [ 71,  70,  67,  59,  48,  43],
        [ 88,  86,  80,  75,  70,  68]],

       [[ 73,  74,  74,  73,  73,  72],
        [ 65,  67,  68,  62,  49,  43],
        [ 60,  64,  67,  50,  13,  -4],
        [103, 107, 109,  90,  51,  33],
        [192, 193, 191, 180, 161, 152],
        [235, 234, 230, 224, 215, 211]],

       [[100, 103, 106,  90,  58,  43],
        [ 92,  95,  98,  79,  41,  23],
        [ 84,  88,  91,  69,  23,   2],
        [121, 124, 128, 113,  80,  65],
        [199, 201, 206, 208, 209, 209],
        [236, 238, 243, 254, 271, 279]],

       [[102, 104, 105,  97,  78,  70],
        [ 98,  99, 100,  89,  67,  57],
        [ 90,  91,  90,  78,  54,  43],
        [ 87,  89,  93,  96,  96,  96],
        [ 90,  94, 109, 141, 191, 213],
        [ 92,  97, 117, 164, 236, 269]],

       [[100, 101, 101,  98,  91,  88],
        [ 98,  98,  97,  91,  81,  77],
        [ 90,  89,  87,  80,  70,  65],
        [ 67,  68,  72,  84, 102, 110],
        [ 31,  36,  55, 102, 175, 208],
        [ 15,  21,  48, 112, 210, 255]]])

In [ ]: