Ask Your Question
-1

Convert numpy arrays to images

asked 2018-05-29 05:16:00 -0600

Kafeel Basha gravatar image

Hello

Consider the object 'train_x' is a numpy array with dimension (10,28,28), can you please help me in converting these 10 array elements into 10 different images using opencv and name accordingly and store in a location, say "E:\Images".

Any reference or example will be helpful.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-05-29 05:37:19 -0600

berak gravatar image

updated 2018-05-29 07:13:40 -0600

this is a really trivial case:

 for i in range(train_x.shape[0]):
      cv2.imwrite("plane"+str(i)+".png", train_x[i])
edit flag offensive delete link more

Comments

Thanks a lot. I ll make sure this will not happen again.

Kafeel Basha gravatar imageKafeel Basha ( 2018-05-29 06:01:09 -0600 )edit
1

I was able to get desired result with below set of codes for i in range(train_x.shape[0]): cv2.imwrite("plane"+str(i)+".png",train_x[i])

Kafeel Basha gravatar imageKafeel Basha ( 2018-05-29 07:01:09 -0600 )edit

apologies, sloppiness here ;)

berak gravatar imageberak ( 2018-05-29 07:13:17 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-05-29 05:16:00 -0600

Seen: 14,832 times

Last updated: May 29 '18