Reputation: 668
I am reading an image via Pillow and converting it to a numpy array.
A = numpy.asarray(Image.open(
ImageNameA).convert("L"))
B = numpy.asarray(Image.open(
ImageNameB).convert("L"))
print A
[[255 255 255 ..., 255 255 255]
[255 255 255 ..., 255 255 255]
[255 255 255 ..., 255 255 255]
...,
[255 255 255 ..., 255 255 255]
[255 255 255 ..., 255 255 255]
[255 255 255 ..., 255 255 255]]
Now when I do any logical operation on these 2 numpy arrays, I get it in form of 'True' and 'False'
Answer = numpy.logical_xor(A,B)
print numpy.logical_xor(A,C)
[[False False False ..., False False False]
[False False False ..., False False False]
[False False False ..., False False False]
...,
[False False False ..., False False False]
[False False False ..., False False False]
[False False False ..., False False False]]
My image processing functions cant work with True, False ... How can i get an image in form of 0 , 255 (in bytes)
Upvotes: 1
Views: 1108
Reputation: 3402
From the question title, I suppose the function you meant to use is actualy numpy.bitwise_xor
it will output arrays in the 0-255 range as you expect.
logical_xor
treats all number above 1 as True
and 0 as False
and always outputs a boolean array (only 0s and 1s).
Upvotes: 4