2

I have a grayscale image that I am reading using the following code:

import pylab as plt
. . .
circle_image = plt.imread(image_gray) #this dimension is 120,120
print(circle_image.shape) # prints (120,120)
plt.imshow(circle_image)
plt.show()

Original Image of 120,120

I am resizing it to 256x256 by using following:

resized_circle_image = misc.imresize(circle_image, (256,256)) # i tried using (256,256,3) but that generates resized image of (256, 256) only
print(resized_circle_image.shape) # prints (256,256)
plt.imshow(resized_circle_image)
plt.show()

resized image of 256,256

I have to concatenate this image with a colored image which is of shape (256,256,3). How do I convert from a none channel to 3 channel image format?

What I tried:

a = np.resize(resized_circle_image, (256, 256, 3))

But that changes the image totally by repeating same image 9 times as follows: Now dimension is 256,256,3 but image is not as expected

Bit Manipulator
  • 248
  • 1
  • 2
  • 17
  • @sascha i tried both the answers there. First one gives (3,256,256) which is channel first and hence not recognized as image. Second one is what I mentioned in my question under 'What I tried' – Bit Manipulator Oct 17 '17 at 18:02
  • Then use [np.swapaxes](https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.swapaxes.html) after (1). – sascha Oct 17 '17 at 18:03

0 Answers0