0

I would like to change my code line "cv2.merge" to command from matplotlib/numpy library. This is my only line in code from cv2 and I don't know how to get rid of it.

dataStretched have max value 1.0, min 0.0 and size 237614. With cv2.merge I merge additional arrays which give a color to the image.

The code:

data1Color=cv2.merge((dataStretched*0,dataStretched*0,dataStretched*1))

Print dataStretched:

[[0.09756098 0.14634146 0.02439024 ... 0.17073171 0.41463415 0.2195122 ]
 [0.07317073 0.09756098 0.12195122 ... 0.2195122  0.19512195 0.17073171]
 [0.04878049 0.07317073 0.09756098 ... 0.2195122  0.2195122  0.14634146]
 ...
 [0.19512195 0.04878049 0.19512195 ... 0.29268293 0.2195122  0.26829268]
 [0.3902439  0.17073171 0.09756098 ... 0.2195122  0.12195122 0.07317073]
 [0.17073171 0.14634146 0.17073171 ... 0.14634146 0.17073171 0.09756098]]

Print data1Color:

[[[0.         0.         0.09756098]
  [0.         0.         0.14634146]
  [0.         0.         0.02439024]
  ...
  [0.         0.         0.17073171]
  [0.         0.         0.41463415]
  [0.         0.         0.2195122 ]]

 [[0.         0.         0.07317073]
  [0.         0.         0.09756098]
  [0.         0.         0.12195122]
  ...
  [0.         0.         0.2195122 ]
  [0.         0.         0.19512195]
  [0.         0.         0.17073171]]

 [[0.         0.         0.04878049]
  [0.         0.         0.07317073]
  [0.         0.         0.09756098]
  ...
  [0.         0.         0.2195122 ]
  [0.         0.         0.2195122 ]
  [0.         0.         0.14634146]]

 ...

 [[0.         0.         0.19512195]
  [0.         0.         0.04878049]
  [0.         0.         0.19512195]
  ...
  [0.         0.         0.29268293]
  [0.         0.         0.2195122 ]
  [0.         0.         0.26829268]]

 [[0.         0.         0.3902439 ]
  [0.         0.         0.17073171]
  [0.         0.         0.09756098]
  ...
  [0.         0.         0.2195122 ]
  [0.         0.         0.12195122]
  [0.         0.         0.07317073]]

 [[0.         0.         0.17073171]
  [0.         0.         0.14634146]
  [0.         0.         0.17073171]
  ...
  [0.         0.         0.14634146]
  [0.         0.         0.17073171]
  [0.         0.         0.09756098]]]
2
  • 1
    data1Color = np.stack([dataStretched*0, dataStretched*0, dataStretched*1], axis=2)
    – HansHirse
    Commented Jun 29, 2021 at 9:52
  • Great, that answer my question, thank You!
    – Gerard
    Commented Jun 29, 2021 at 10:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.