Python - NumPy Array Logical XOR operation byte wise
<p>I am reading an image via Pillow and converting it to a numpy array.</p>

<pre><code>        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]]
</code></pre>

<p>Now when I do any logical operation on these 2 numpy arrays, I get it in form of 'True' and 'False'</p>

<pre><code>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]]
</code></pre>

<p>My image processing functions cant work with True, False ... How can i get an image in form of 0 , 255 (in bytes)</p>

<p>From the question title, I suppose the function you meant to use is actualy <code>numpy.bitwise_xor</code> it will output arrays in the 0-255 range as you expect. </p>

<p><code>logical_xor</code> treats all number above 1 as <code>True</code> and 0 as <code>False</code> and always outputs a boolean array (only 0s and 1s).</p>

python numpy pillow