1

lets say i have an image presented as this numpy array:

array([[ 55, 229, 185,  21, 128,  50, 109, 121, 251],
   [138,   0, 143, 153,  22, 244, 102,   6,  63],
   [250, 235,  57,  28, 220,  15, 217, 147,  70],
   [121, 164, 128, 224,  56, 206, 104,  87, 154],
   [232,  51,  20, 235,   8, 200, 119, 234, 180],
   [182,  79,  79,  22, 221, 233,  54,  11, 209],
   [249,  64,  92,  70, 167, 151, 214, 188, 213]], dtype=uint8)

this is 7X9 matrix and i want to double the width of the image to 7x18. i know what to do when you want to compress an image, but im not sure what i supposed to do if i want to increase the size.

thanks!

`

3
  • 1
    How do you want to double it? Do you want to end up with a 7x18 array, or just change how it looks when plotted? Do you want to duplicate each column? Linearly interpolate to generate in-between columns? Pad with zeros on one side that you can fill in later? The question is vague right now. Commented Jan 25, 2017 at 0:13
  • As Ben said, it's very vague. Maybe you want to fill in zeros, maybe you want to interpolate (the same as resizing in video-players). The former is basic numpy stuff, the latter can be done with scipy or scikit-image. Commented Jan 25, 2017 at 4:10
  • i need to end up with 7x18 array, i dont really care about the quality of the results, just a way to do it. Commented Jan 25, 2017 at 10:37

1 Answer 1

1

Put your array in a, then

np.repeat(a, 2, axis=1)

gives

array([[ 55,  55, 229, 229, 185, 185,  21,  21, 128, 128,  50,  50, 109,
    109, 121, 121, 251, 251],
   [138, 138,   0,   0, 143, 143, 153, 153,  22,  22, 244, 244, 102,
    102,   6,   6,  63,  63],
   [250, 250, 235, 235,  57,  57,  28,  28, 220, 220,  15,  15, 217,
    217, 147, 147,  70,  70],
   [121, 121, 164, 164, 128, 128, 224, 224,  56,  56, 206, 206, 104,
    104,  87,  87, 154, 154],
   [232, 232,  51,  51,  20,  20, 235, 235,   8,   8, 200, 200, 119,
    119, 234, 234, 180, 180],
   [182, 182,  79,  79,  79,  79,  22,  22, 221, 221, 233, 233,  54,
     54,  11,  11, 209, 209],
   [249, 249,  64,  64,  92,  92,  70,  70, 167, 167, 151, 151, 214,
    214, 188, 188, 213, 213]])

Which has shape 7x18.

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.