How can I add an outline to an image?
<p>I'm fairly new to Python, and I have a python function that adds an outline to an image. However, the function currently adds the outline one pixel inside the image, instead of on the outside like it should. How can I modify this to make the outline further out by 1 pixel?</p>

<pre><code>def addOutline(imageArray):
    from statistics import mean
    newAr = imageArray
    newAr.flags.writeable = True
    balance = 250
    for i0 in range(1,len(newAr)):
        for i in range(1,len(newAr[i0])):
            if mean(newAr[i0][i][:3]) &gt; balance and mean(newAr[i0][i-1][:3]) &lt; balance:
                newAr[i0][i-1][:3] = 40
            if mean(newAr[i0][i][:3]) &lt; balance and mean(newAr[i0][i-1][:3]) &gt; balance:
                newAr[i0][i][:3] = 40
            if mean(newAr[i0][i][:3]) &lt; balance and mean(newAr[i0-1][i][:3]) &gt; balance:
                newAr[i0][i][:3] = 40
            if mean(newAr[i0][i][:3]) &lt; balance and mean(newAr[i0+1][i][:3]) &gt; balance:
                newAr[i0][i][:3] = 40

    return newAr
</code></pre>

<p>I guess if you really want the outline to be outside the figure. You need to create a new image array with size <code>(len(newAr)+1)*(len(newAr[0]+1))</code>, where the extra pixel is to put your line. All the other pixels inside should be copied from your original image. </p>

python image python-3.x pillow