0

I want to convert an image first into 2-D, then into 1-D array. I used reshape in order to do that. I converted image1.png which has 64x64x3 pixels into an array which has the size 1x12288. However, when I try to copy and display the first 100 values I get an empty array. Can you help me please?

Test Image(image1)

from PIL import Image
from scipy.misc import imread
import numpy as np

img1 = imread('image1.png')
img1 = np.reshape(img1,(128,96))

y = list(np.reshape(img1,(1,12288)))
z = y[1:101]

print(z)
2
  • You have posted a JPG but your code opens a PNG? Please click edit under your question and post the actual image and the actual code. Commented Aug 12, 2018 at 15:53
  • The image you have posted is still a JPEG, but with a PNG extension. You have created or obtained a bad image somehow. Commented Aug 12, 2018 at 16:00

2 Answers 2

2

You don't create a 1D-array, but a 2D-array with one row, and you try to get second to 100th row (Python indices are 0-based).

from PIL import Image
from scipy.misc import imread
import numpy as np

img1 = imread('image1.png')
y = list(img1.ravel())
z = y[:100]

print(z)
Sign up to request clarification or add additional context in comments.

Comments

1

instead of

z = y[1:101]

you should try

z = y[0][1:101]

or make changes to reshape() call to make it really 1D array

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.