0
$\begingroup$

I've created masks(numpy array with 0,1 as values) and tried exporting this array to jpg using matplolib but it's not exporting the values as it is. I'm getting a range of pixel values in resulting image. Is there any way in which I can add the array values to pixel values as it is. For example numpy array is 40X40 and resulting jpg image resolution is 40X40 pixels.

$\endgroup$
0
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ What if I have multiple classes like 0,1,2,3,4,5, etc? $\endgroup$ Jul 1 '19 at 6:30
  • $\begingroup$ For my problem mask has values 1.5, 3, 3.5, 4, 4.5, 5. $\endgroup$ Jul 1 '19 at 6:31
  • $\begingroup$ Having multiple classes is possible. You can force the rescaling not to happen while saving. $\endgroup$ Jul 2 '19 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.