Storing masks in jpg format
When you simply use say plt.savefig() to jpg, matplotlib by default does not save it to a binary image as you require. JPG by default the definition is values ranging from 0-255. 
Suggest using PIL instead of matplotlib then you can save as BW binary image.