3

I have a matrix m filled as below(condensed version). Can you please help me to create a image from it. Such that I want all 10 in the matrix to be in different color.

m = np.array([[ 1 0 .... -1 10],  [ 10,0, ..... 0, 10] .... ]])

The dimension of this matrix is x rows and y columns.

To make it simple, I don't need a color image.

import cv2
import numpy as np
img = np.random.randint(222, size=(100, 100,3))
gen = np.array(img ,dtype=np.uint8)
cv2.imshow('i',img)
cv2.waitKey(0)
cv2.destroyWindow('i')
3
  • 1
    In python opencv, images are just numpy arrays. So your m matrix is already an image, just define image type when creating array: np.array([[...]],dtype=np.uint8). Use cv2.imshow('image',m) to display it. Commented Nov 11, 2017 at 21:55
  • @zindarod - I tried like you said it plots a black image. Please check my sample code. Commented Nov 11, 2017 at 22:19
  • 1
    cv2.imshow('i',gen) Commented Nov 11, 2017 at 22:32

1 Answer 1

1
import cv2
import numpy as np
img = np.random.randint(222, size=(100, 100,3))
gen = np.array(img ,dtype=np.uint8)
cv2.imshow('i',gen)
cv2.waitKey(0)
cv2.destroyWindow('i')
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.