0

I am using Opencv 4.1.0 with python 3.

I resized a 480 X 640 size original image to 500 x 500 that works fine.

Again resized the 500 X 500 image to 25000 X 1 . I am doing this for the purpose of facial recognition using PCA.

Again when I resized the image from 25000 X 1 to 500 X 500 , it did not display the 500 X 500 image . It instead displayed a error output of black and white vertical lines.

Can someone please point out what is going wrong here ? Thanks in advance.

import cv2
import numpy as np
image=cv2.imread('C://Users//raghu//Documents//Faces//gt_db//unique//IMG1.jpg',0)
I1=cv2.resize(image,(500,500))
I2=cv2.resize(I1,(25000,1))
I3=cv2.resize(I2,(500,500))
cv2.imshow('480x640',image)
cv2.imshow('25000X1',I2)
cv2.imshow('500x500',I1)
cv2.imshow('2-500X500',I3)
cv2.waitKey(0)
cv2.destroyAllWindows()

Resizing to I1 works fine.Expecting the output of I3 same as I1.

1
  • That is to be expected. When you resize to 1 row or column, you lose information, which cannot be recovered by resizing larger again. Commented Aug 21, 2019 at 23:16

1 Answer 1

2

By downsizing to 1 pixel you loose nearly all image information as all y-pixels get interpolated to a single number per x-pixel. By resizing back that pixel is then copied vertically to 500px, so I expect you to get a stripy pattern.

You should not resize, you have to reshape. That means putting the pixel values from a 2d array to a 1d array, that is what the PCA algorithm expects.

Example:

# create 2d array
y = np.array(range(9)).reshape(3,3)
print(y)

[[0 1 2]
[3 4 5]
[6 7 8]]

# reshape to 1d
x = y.reshape(-1)
print(x)
print(x.shape[:2])

[0 1 2 3 4 5 6 7 8]
(9,)

reshape documentation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.