-1

I want to convert the given matlab code to python

img_o = repmat(fill_value, osize);

here fill_value is a 1x1x3 matrix and osize=[320 320] output matrix is 320x320x3

I have tried

img_o = tile(fill_value, osize)

where

fill_value = numpy.array([[[0, 0, 0]]])
osize=[320,320]

here i am getting a matrix of 1x320x960 instead of 320x320x3 matrix please help to solve

diva
  • 239
  • 1
  • 5
  • 13

1 Answers1

1

Numpy does some nonintuitive stuff that it nonintuitively calls "broadcasting". Here's what you need (just one more explicit dimension on your size vector):

>>> osize = (320, 320, 1)
>>> img_o = numpy.tile(fill_value, osize)
>>> img_o.shape
(320, 320, 3)
hobs
  • 18,473
  • 10
  • 83
  • 106