Closed ghost closed 7 years ago
This issue can be fixed by specifying a uint8 datatype on line 60, which prevents the numpy array being created as a boolean array, which won't work with my RGB code. This causes further problems though, it seems numpy isn't playing well with the 1bpp non-indexed datatype. The solution I found is to replace lines 58-62 with this:
print ("Saving Image");
dt = im.getdata(0);
imout = np.array(dt, dtype=np.uint8).reshape((im.height, im.width));
imout[imout>0] = 255;
out = imout[:,:,np.newaxis];
out = np.repeat(out, 3, axis=2);
Going via the im underlying data seems to play better, but you then have to reshape it, and make sure that any 1s become 255 etc. I probably won't commit this change at the moment, because without further testing I'm not 100% sure it'll work with all other datatypes. There may also be a much more efficient way of doing this, perhaps skipping numpy complete.
P.s. Interesting choice of image :)
I've now adjusted the code to completely avoid numpy, as it isn't necessary here. It should be faster, and doesn't have a problem with 1bpp image types. Hopefully it'll work for you!
Mike
works perfectly fine. Thanks
Just tested it with the attached image .
It is an "PNG image data, 619 x 995, 1-bit grayscale, non-interlaced"
The result was a crash
It works fine when converting the input to "PNG image data, 619 x 995, 1-bit colormap, non-interlaced"