Check that all your png images 0.png, 1.png, ... 9.png all exist, are in the correct location and have non-zero dimensions when you load them via imread. There's nothing otherwise wrong with the code - it works for me when I load my own png image using your code.