Resize without changing the structure of the image
<p>I have an image here (DMM_a01_s01_e01_sdepth.PNG, it is basically a human depth map or something, I don't really know the details :( ):</p>

<p><a href="http://i.stack.imgur.com/2Ux3i.png" rel="nofollow"><img src="http://i.stack.imgur.com/2Ux3i.png" alt="DMM_a01_s01_e01_sdepth.PNG"></a></p>

<p>It's very small (54x102) so here is a visualization:
<a href="http://i.stack.imgur.com/LRSJV.png" rel="nofollow"><img src="http://i.stack.imgur.com/LRSJV.png" alt="enter image description here"></a></p>

<p>But when I tried to resize it to 20x20 using this piece of code that I've made:</p>

<pre><code>from scipy import misc
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import numpy as np
import math
import cv2

im = misc.imread('DMM_a01_s01_e01_sdepth.PNG')

def rgb2gray(rgb):
    return np.dot(rgb[...,:3], [0.299, 0.587, 0.114])

if len(im.shape) ==3:
    im = rgb2gray(im) # Convert RGB to grayscale

# Show image
plt.imshow(im, cmap = cm.Greys_r)
plt.show()

# Resize image

boxSize = 20
newImage= misc.imresize(im, (boxSize,boxSize), interp="bicubic")
plt.imshow(newImage, cmap = cm.Greys_r)
plt.show()
</code></pre>

<p>, the resized image is no longer the same as the orignal one:</p>

<p><a href="http://i.stack.imgur.com/GKLye.png" rel="nofollow"><img src="http://i.stack.imgur.com/GKLye.png" alt="enter image description here"></a></p>

<p>How do I resize and still keep the structure of the image? Please help me, thank you very much :) </p>

<p>What you are asking for is impossible. Resizing of image is a destructive operation. You have 54x102 pixels (5508 pixels of data) and you are trying to fit that amount of data into a 20x20 image - that's just 400 pixels! You'll always lose some detail, structure etc. based on the algorithm you used - in this case scipy's.</p>

python image-processing