python - Error when transforming numpy array to PIL Image -
i have variable img
int64 numpy.array
sizes 28x28. content looks this:
[...] [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0 0 0 68 154 188 176 254 254 254 254 254 227 106 17 0 0 0 0 0 0 0] [...]
i want convert array pil image. call img = image.fromarray(img, mode='l')
output 0s while obvious shouldn't that. have checked mode
options , seems l correct. checked other answers inside stackoverflow , couldn't find reproduces particular problem.
l (8-bit pixels, black , white)
why "simple" piece of code given unexpected behaviour?
thanks in advance!
as @divakar pointed out, data types not coherent.
just adding np.uint8()
works:
img = image.fromarray(np.uint8(img), mode='l')
Comments
Post a Comment