Basics of binarized image processing with Python

Image processing

This is image processing that is often used to process and analyze images. If you remember, you can reduce the number of image files, so it's good to remember.

Binary image

Also called a grayscale image. To be black and white. It is the basis of image processing.

environment

・ Jupyter notebook ・ Python version == 3.7.4 ・ Sample.jpg (from http://free-photo.net/archive/entry10252.html) sample1.jpg

Source code

#import of opencv and numpy
import cv2
import numpy as np

#Loading images
img = cv2.imread("sample1.jpg ")

#Grayscale conversion
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

#Threshold setting
threshold_value = 150

#Array creation (for output)
threshold_img = gray.copy()

#Implementation(numpy)
threshold_img[gray < threshold_value] = 0
threshold_img[gray >= threshold_value] = 255

#Output
cv2.imwrite("C:\\Users\\[username]\\python\\sample1-2.jpg ",threshold_img)

Output image result

sample1-2.jpg

At the threshold setting, if you try using a different number instead of "150", you will see a black and white position change. imageJ(URL:"https://imagej.nih.gov/ij/") If you use software such as, you can see such changes in real time, so you should try it.

Recommended Posts

Basics of binarized image processing with Python
Image processing with Python
Drawing with Matrix-Reinventor of Python Image Processing-
Image processing with Python (Part 2)
Image processing with Python (Part 1)
Image processing with Python (Part 3)
[Python] Image processing with scikit-image
Image processing by matrix Basics & Table of Contents-Reinventor of Python image processing-
Real-time image processing basics with opencv
Getting Started with Python Basics of Python
Image processing with Python 100 knocks # 3 Binarization
Image processing with Python 100 knocks # 2 Grayscale
python image processing
Basics of Python ①
Basics of python ①
Image processing with Python 100 knock # 10 median filter
Python: Basics of image recognition using CNN
Image processing with Python 100 knocks # 8 Max pooling
Grayscale by matrix-Reinventor of Python image processing-
Image processing with Python & OpenCV [Tone Curve]
Image processing with Python 100 knock # 12 motion filter
Easy image processing in Python with Pillow
Image processing with Python 100 knocks # 7 Average pooling
Light image processing with Python x OpenCV
Matrix Convolution Filtering-Reinventor of Python Image Processing-
Image processing with Python 100 knocks # 9 Gaussian filter
Image processing with Python 100 knocks # 4 Binarization of Otsu (discriminant analysis method)
Image processing with MyHDL
Basics of Python scraping basics
First Python image processing
# 4 [python] Basics of functions
Basics of python: Output
Various processing of Python
Image Processing with PIL
Color page judgment of scanned image with python
Image processing from scratch with python (5) Fourier transform
Image processing from scratch with python (4) Contour extraction
Image processing? The story of starting Python for
Image Processing with Python Environment Setup for Windows
100 Language Processing with Python Knock 2015
Extract the table of image files with OneDrive & Python
Image processing with PIL (Pillow)
"Apple processing" with OpenCV3 + Python3
Notes on HDR and RAW image processing with Python
Image editing with python OpenCV
Acoustic signal processing with Python (2)
[OpenCV / Python] I tried image analysis of cells with OpenCV
Acoustic signal processing with Python
[Chapter 5] Introduction to Python with 100 knocks of language processing
Sorting image files with Python (2)
Sorting image files with Python (3)
Parallel processing with Parallel of scikit-learn
python: Basics of using scikit-learn ①
Tweet with image in Python
Sorting image files with Python
[Chapter 3] Introduction to Python with 100 knocks of language processing
Image processing by python (Pillow)
Post processing of python (NG)
[Chapter 2] Introduction to Python with 100 knocks of language processing
Image Processing Collection in Python
[Basics of Modern Mathematical Statistics with python] Chapter 1: Probability