convert rgb image to binary in pillow

from PIL import Image 
image_file = Image.open("cat-tied-icon.png") # open colour image
image_file = image_file.convert('1') # convert image to black and white
image_file.save('/tmp/result.png')

4.25
4
John Stone 70 points

                                    from PIL import Image

col = Image.open("cat-tied-icon.png")
gray = col.convert('1')
bw.save("result_bw.png")

4.25 (4 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
python how to convert PIL.Image.Image to binary pil image to binary pillow image to binary string python image to binary python Pillow python convert pil image to binary converting rgb data to image pillow python pil convert binary data to image python binary to image pillow PIl image to convert into Ptr<cv::UMat> convert rgb image to black and white python pillow alpha_composite image convert L pil image object pil make image python pil image convert white in rgb python python image getdata set pil image mode pil image return PIL image python image function pil image from binary new pil image how to composite images in pil with x and y axis pil blank image form size open bytes in pillow pil load left to right PIL view image mode python show image mode python im.convert('0') python im.convert('1') pil python putpixel rgba pil image convert format pil python convert("L") pil new image python pillow new black image python image new grayscale Image.open() modes python image module image.format is none after rotation convert an image to rgb color mode PIL image change bgr values to black and white without numpy array how to put image created by pil new in a variable in python pil resize rgb python pillow move image pil image new() pil class to image html string to image python pil python convert RGB to black and white I.convert('L') past the image in center pillow opil change image name PIL.convert('l') in python PIL image new python python pil picture moving PIL get image pillow print image type pil image.open rgb pillow python resize image sRGB PIL mode L python pillow composite pil create image alpha composite pillow image.new python PIllow open binary image reload image on change pil how to use PIL.Image.new pil image convert PIL saves images all white pil image getdata rgb white in python pil img from array alpha image binary with pillow image = Image.new('1', size, color) Python PIL Color pil resize vlaues are zero why converting image in PIL color pillow create image from pixel array pil image open pil change image mode pil.image.new example pillow python convert PIL new image object how to print Imaging Core object python pil image tobytes rgb to black and white python pillow image object python pil image open convert PIL image to rb pillow image open allk white convert rgb image to binary in pillow
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source