{"action":"created","issue":{"url":"https://api.github.com/repos/scipy/scipy/issues/5223","labels_url":"https://api.github.com/repos/scipy/scipy/issues/5223/labels{/name}","comments_url":"https://api.github.com/repos/scipy/scipy/issues/5223/comments","events_url":"https://api.github.com/repos/scipy/scipy/issues/5223/events","html_url":"https://github.com/scipy/scipy/issues/5223","id":104886603,"number":5223,"title":"Zoom does not return the same values when resizing a sub-array relative to the entire array","user":{"login":"GeertLitjens","id":5407440,"avatar_url":"https://avatars.githubusercontent.com/u/5407440?v=3","gravatar_id":"","url":"https://api.github.com/users/GeertLitjens","html_url":"https://github.com/GeertLitjens","followers_url":"https://api.github.com/users/GeertLitjens/followers","following_url":"https://api.github.com/users/GeertLitjens/following{/other_user}","gists_url":"https://api.github.com/users/GeertLitjens/gists{/gist_id}","starred_url":"https://api.github.com/users/GeertLitjens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GeertLitjens/subscriptions","organizations_url":"https://api.github.com/users/GeertLitjens/orgs","repos_url":"https://api.github.com/users/GeertLitjens/repos","events_url":"https://api.github.com/users/GeertLitjens/events{/privacy}","received_events_url":"https://api.github.com/users/GeertLitjens/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-04T13:02:47Z","updated_at":"2015-09-30T04:15:21Z","closed_at":null,"body":"When you resize a sub-array with a factor of 3 (or higher) the result should be the same when resizing the entire array and then taking the same sub-array (3 times larger of course). However, when using zoom it is not, regardless of interpolation order\r\n\r\nCode to reproduce:\r\n\r\n    import numpy\r\n    from scipy.ndimage import zoom\r\n    from scipy.misc import imresize\r\n    arr = numpy.array(range(36))\r\n    arr.shape = (6,6)\r\n    res = zoom(arr, 3., order=0)\r\n    res_sub = zoom(arr[0:4,0:4], 3., order=0)\r\n    numpy.abs(res[0:12,0:12] - res_sub).sum()\r\n\r\nThe last result should return zero, but it does not. When using imresize, the result is as expected:\r\n\r\n    arr = numpy.array(range(36))\r\n    arr.shape = (6,6)\r\n    res = imresize(arr, 3., interp='nearest', mode='F').astype(int)\r\n    res_sub = imresize(arr[0:4,0:4], 3., interp='nearest', mode='F').astype(int)\r\n    numpy.abs(res[0:12,0:12] - res_sub).sum()\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/scipy/scipy/issues/comments/144276892","html_url":"https://github.com/scipy/scipy/issues/5223#issuecomment-144276892","issue_url":"https://api.github.com/repos/scipy/scipy/issues/5223","id":144276892,"user":{"login":"stefanv","id":45071,"avatar_url":"https://avatars.githubusercontent.com/u/45071?v=3","gravatar_id":"","url":"https://api.github.com/users/stefanv","html_url":"https://github.com/stefanv","followers_url":"https://api.github.com/users/stefanv/followers","following_url":"https://api.github.com/users/stefanv/following{/other_user}","gists_url":"https://api.github.com/users/stefanv/gists{/gist_id}","starred_url":"https://api.github.com/users/stefanv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stefanv/subscriptions","organizations_url":"https://api.github.com/users/stefanv/orgs","repos_url":"https://api.github.com/users/stefanv/repos","events_url":"https://api.github.com/users/stefanv/events{/privacy}","received_events_url":"https://api.github.com/users/stefanv/received_events","type":"User","site_admin":false},"created_at":"2015-09-30T04:15:21Z","updated_at":"2015-09-30T04:15:21Z","body":"This won't happen with, e.g., ``skimage.transform.rescale`` either.  My first thought was that this is because ndimage thinks of data values as the centres of pixels.  But I've now simulated several indexing mechanisms and none of them seem right:\r\n\r\n```\r\nfrom scipy import ndimage as ndi\r\nimport numpy as np\r\n\r\ny = np.array([1, 2, 3, 4])\r\n\r\nprint('Method: ndimage')\r\nprint(ndi.zoom(y, 3, order=0))\r\n\r\nprint('\\n---------------------------------------------------')\r\nprint('Method: center coordinates')\r\nprint('Image looks like this:')\r\nprint('''\r\nPixels:         [       ][       ][       ][       ]\r\nIndices:            0        1        2        3\r\nZoomed pixels:  [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]\r\nZoomed indices:  0  1  2  3  4  5  6 ...\r\n''')\r\ndelta = (4 / 12) / 2\r\nx = np.linspace(delta, 3.5 - delta, 4 * 3, endpoint=True)\r\nprint(y[(x).astype(int)])\r\n\r\nprint('\\n---------------------------------------------------')\r\nprint('Method: data coordinates')\r\nprint('Image looks like this:')\r\nprint('''\r\nPixels:          .      .      .       .\r\nIndices:         0      1      2       3\r\nZoomed pixels:   . . . . . . . . . . . .\r\nZoomed indices:  0 1 2 3 4 5 6 ...\r\n''')\r\nx = np.linspace(0, 3, 4 * 3, endpoint=True)\r\nprint(y[x.astype(int)])\r\n\r\nprint('\\n---------------------------------------------------')\r\nprint('Method: geometric data coordinates')\r\nprint('Image looks like this:')\r\nprint('''\r\nPixels:          .     .     .     .\r\nIndices:         0     1     2     3\r\nZoomed pixels:   . . . . . . . . . . . .\r\nZoomed indices:  0 1 2 3 4 5 6 ...\r\n''')\r\nx = np.linspace(0, 11/3, 4 * 3, endpoint=True)\r\nprint(y[x.astype(int)])\r\n```\r\n\r\nOutput:\r\n\r\n```\r\nMethod: ndimage\r\n[1 1 2 2 2 2 3 3 3 3 4 4]\r\n\r\n---------------------------------------------------\r\nMethod: center coordinates\r\nImage looks like this:\r\n\r\nPixels:         [       ][       ][       ][       ]\r\nIndices:            0        1        2        3\r\nZoomed pixels:  [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]\r\nZoomed indices:  0  1  2  3  4  5  6 ...\r\n\r\n[1 1 1 2 2 2 2 3 3 3 4 4]\r\n\r\n---------------------------------------------------\r\nMethod: data coordinates\r\nImage looks like this:\r\n\r\nPixels:          .      .      .       .\r\nIndices:         0      1      2       3\r\nZoomed pixels:   . . . . . . . . . . . .\r\nZoomed indices:  0 1 2 3 4 5 6 ...\r\n\r\n[1 1 1 1 2 2 2 2 3 3 3 4]\r\n\r\n---------------------------------------------------\r\nMethod: geometric data coordinates\r\nImage looks like this:\r\n\r\nPixels:          .     .     .     .\r\nIndices:         0     1     2     3\r\nZoomed pixels:   . . . . . . . . . . . .\r\nZoomed indices:  0 1 2 3 4 5 6 ...\r\n\r\n[1 1 1 2 2 2 3 3 3 4 4 4]\r\n```"}}