same binary image - different in python & matlab
<p>OK.  I'm thoroughly confused.  I have a binary image.  The values are (allegedly) 0 and 1.  I read it in Matlab, to verify:</p>

<pre><code>binaryImage = imread('binary.png');
</code></pre>

<p>I get the max and min values, and the values are 1 and 0, respectively.</p>

<pre><code>maxValue = max(binaryImage(:));
minValue = max(binaryImage(:));
</code></pre>

<p>I take the same exact binary image, and read it in Python...</p>

<pre><code>from scipy.misc import imread
</code></pre>

<p>to get the pixel values we flatten it</p>

<pre><code>li = img.flatten()

# check each value
for s in li:
    print s
</code></pre>

<p>The values, according to Python, are 0 and <strong>255</strong>.</p>

<p>So... does this mean if I use C++ (ITK) I will get a different value?  If I use OpenCV I will get a different value?  (Technically the "on" values should only be 1 and 255, but you know what I mean.)</p>

<p>If the pixel is "on" (white), and I set the value to 1 (in a binary image), no matter what language I read it in, I expect to see <strong>1</strong> for that value.</p>

<p>How come it's different?</p>

<p>Thanks!</p>

<p>matlab supports logical arrays and scipy converts the image to grayscale. Depending on what you want to do you can convert the grayscale image to logicals</p>

<pre><code>bit_img = img &gt; 127
</code></pre>

<p>or convert the logical array to int8 in matlab</p>

<pre><code>img = int8(binary_image) * 255
</code></pre>

python matlab image-processing