0

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 :( ):

DMM_a01_s01_e01_sdepth.PNG

It's very small (54x102) so here is a visualization: enter image description here

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

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()

, the resized image is no longer the same as the orignal one:

enter image description here

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

Community
  • 1
  • 1
Dang Manh Truong
  • 795
  • 2
  • 10
  • 35
  • when you say structure do you mean keeping the image the same shape, so that the person still looks tall and skinny or do you mean making it still have the same level of detail as the original? – Chachmu Sep 12 '16 at 11:31
  • @Chachmu I think it should have the same level of detail as the original, but to be honest I'm not 100% sure :( I just think it should look as much as the orignal image as possible :( – Dang Manh Truong Sep 12 '16 at 11:34
  • Possibly related: http://stackoverflow.com/q/273946/1025391 – moooeeeep Sep 12 '16 at 11:36
  • The original is a rectangle but `(boxSize, boxSize)` would seem to make it square, no? So it will be stretched/squashed. – Peter Wood Sep 12 '16 at 11:39
  • Why are you expecting the same level of detail? You're changing the aspect ratio, and the original image has almost ten times as many pixels as the resized version. – PM 2Ring Sep 12 '16 at 11:40
  • @moooeeeep Tried but it did not work for me :( – Dang Manh Truong Sep 12 '16 at 12:24
  • @PM2Ring I know but can't we use some techniques like histogram equalization or thresholding to rectify the situation? :( – Dang Manh Truong Sep 12 '16 at 13:54

1 Answers1

0

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.

iScrE4m
  • 882
  • 1
  • 12
  • 31