convert coordinates into binary image python
<p>I made a GUI in which I can load an image from disk and convert the mouse motion ( drawing the contours ) into coordinates. Now I need to convert the coordinates into a binary image and I don't know how. 
Here is my code:</p>

<pre><code>from Tkinter import *
from tkFileDialog import askopenfilename
from PIL import Image, ImageTk
import numpy as np
import cv2

class Browse_image :
 def __init__ (self,master) :

  frame = Frame(master)
  frame.grid(sticky=W+E+N+S)
  self.browse = Button(frame, text="Browse", command = lambda: browseim(self))
  self.browse.grid(row=13, columnspan=1)
  self.photo = PhotoImage(file="browse.png")
  self.label = Label(frame, image=self.photo)
  self.label.grid(row=1,rowspan=10)
  self.label.bind('&lt;B1-Motion&gt;', self.mouseevent)
 def mouseevent(self,event):
   w=self.photo.width()
   h=self.photo.height()
   a = np.zeros(shape=(h,w))
   #print event.x, event.y
   a[event.x,event.y]=1
</code></pre>

<p>plt.imsave('binary.png', a, cmap=cm.gray)</p>

<pre><code>def browseim(self):
  path = askopenfilename(filetypes=(("png files","*.png"),("jpeg files",
   "*.jpeg")) )
  if path:
    img = Image.open(path)
    self.photo = ImageTk.PhotoImage(img)                    
    self.label.configure(image = self.photo)
   #self.label.image = self.photo


root= Tk()
b= Browse_image(root)
root.mainloop()
</code></pre>

<p>`</p>

<p>Your issue is that you are creating a new empty array at each mouse event with the line <code>a = np.zeros(shape=(h,w))</code> in mouseevent. To fix that you should have <code>a</code> declared in the <code>__init__</code> as an attribute (ie <code>self.a = np.zeros(shape=(h,w))</code>) so that you can acces and update it without overwriting it in your <code>mouseevent</code> function.</p>

python tkinter