PIL rotate image colors (BGR -> RGB)
I know it’s an old question, but I had the same problem and solved it with: img = img[:,:,::-1]
I know it’s an old question, but I had the same problem and solved it with: img = img[:,:,::-1]
I had the same problem and I solved that by upgrading this package using the command below: pip install -U Pillow
I agree with almost everything as answered by “unutbu” and Ignacio Vazquez-Abrams, however… EXIF Orientation flag can have a value between 1 and 8 depending on how the camera was held. Portrait photo can be taken with top of the camera on the left, or right edge, landscape photo could be taken upside down. Here … Read more
tl;dr Does x contain uint values in [0, 255]? If not and especially if x ranges from 0 to 1, that is the reason for the error. Explanation Most image libraries (e.g. matplotlib, opencv, scikit-image) have two ways of representing images: as uint with values ranging from 0 to 255. as float with values ranging … Read more
You could try using Pillow instead, which is a PIL fork: pip install Pillow To import use: from PIL import Image
On Ubuntu, you need to have libfreetype-dev installed before compiling PIL. i.e. $ sudo apt-get install libfreetype6-dev $ sudo -s \# pip uninstall pil \# pip install –no-cache-dir pil PS! Running pip install as sudo will usually install packages to /usr/local/lib on most Ubuntu versions. You may consider to install Pil in a virtual environment … Read more
Yes OpenCV is more robust and flexible and can perform most of the image processing routines which are available out there, So probably this filter can be done with OpenCV> However, there may not be a straightforward API for that. Anyways, as far as the conversion of image format from OpenCV to PIL is concerned … Read more
Remember to call buf.seek(0) so Image.open(buf) starts reading from the beginning of the buf: import io from PIL import Image import matplotlib.pyplot as plt plt.figure() plt.plot([1, 2]) plt.title(“test”) buf = io.BytesIO() plt.savefig(buf, format=”png”) buf.seek(0) im = Image.open(buf) im.show() buf.close()
You should use convert() method: from PIL import Image im = Image.open(“Ba_b_do8mag_c6_big.png”) rgb_im = im.convert(‘RGB’) rgb_im.save(‘colors.jpg’) more info: http://pillow.readthedocs.io/en/latest/reference/Image.html#PIL.Image.Image.convert
Might be a nicer way, but this should work tuple([10*x for x in img.size])