[PYTHON] Convert the image data (png) at hand to a .pbm image

I was thinking of doing it with opencv, The pillow is more like a beginner, so try it first.

png_to_pbm.py



#Enable when displaying with jupyter.
#%matplotlib inline

from PIL import Image
import os
import matplotlib.pyplot as plt

file_name = 'piet.png'

#Open image file
img = Image.open(file_name)

#Convert to 1bit? Meaning of?
img_pbm = img.convert('1')
img_pbm.save('piet.pbm')
plt.imshow(img_pbm)

#'L'Then it becomes grayscale
#img_pgm = img.convert('L')

#'RGB'Then it becomes RGB
#img_ppm = img.convert('RGB')


If you want to resize, follow below.

png_to_pbm.py continued


lf_img_resize = lf_img.resize((512,128))
lf_img_resize.save('lf_img_resize.pbm')
plt.imshow(lf_img_resize)

Recommended Posts

Convert the image data (png) at hand to a .pbm image
Convert a string to an image
Convert PDF to image (JPEG / PNG) with Python
Convert the image in .zip to PDF with Python
[python] Change the image file name to a serial number
Challenge image classification by TensorFlow2 + Keras 2 ~ Let's take a closer look at the input data ~
Dot according to the image
Image crawling summary performed at the speed of a second
Build a Python environment and transfer data to the server
The image is a slug
[Go] Create a CLI command to change the extension of the image
I tried to cut out a still image from the video
Convert A4 PDF to A3 every 2 pages
Workflow to convert formula (image) to python
Convert PDF to image with ImageMagick
A tool to convert Juniper config
How to divide and process a data frame using the groupby function
How to send a visualization image of data created in Python to Typetalk
Try to image the elevation data of the Geographical Survey Institute with Python
How to put a line number at the beginning of a CSV file
[To Twitter gentlemen] I wrote a script to convert .jpg-large to .jpg at once.
Prepare a URL to display the image uploaded by Active Storage by yourself
[Development environment] How to create a data set close to the production DB
Start the webcam to take a still image and save it locally
Convert xml format data to txt format data (yolov3)
Convert memo at once with Python 2to3
[Python] How to convert a 2D list to a 1D list
Give a title to the ipywidgets tab
Convert psd file to png in Python
Convert Excel data to JSON with python
Cut out A4 print in the image
Use pandas to convert grid data to row-holding (?) Data
Convert FX 1-minute data to 5-minute data with Python
Convert PDF files to PNG files with GIMP
Convert HEIC files to PNG files with Python
Sample to convert image to Wavelet with Python
The story of IPv6 address that I want to keep at a minimum
I want to make a music player and file music at the same time
Paste a link to the data point of the graph created by jupyterlab & matplotlib
Change the data frame of pandas purchase data (id x product) to a dictionary
I tried to process and transform the image and expand the data for machine learning
Convert the cURL API to a Python script (using IBM Cloud object storage)
[Introduction to Python] How to get the index of data with a for statement