top of page

Image processing with open CV and pillow

  • 작성자 사진: Shin Yoonah, Yoonah
    Shin Yoonah, Yoonah
  • 2022년 7월 14일
  • 2분 분량

최종 수정일: 2022년 8월 8일


What is a digital image?

Digital image is a rectangular array of numbers.

Image is comprised of rectangular grid of blocks called pixels

Pixel number is also called "Intensity values"


Digital images have intensity values between zero to 255

= 256 different intensity values to represent an image


*There is a color difference by the values of intensity colors*


Bar indicates gray intensity color

This bar demonstrates the relationship between shades of gray and the numerical values.

Darker shades of gray = lower values with 0 (black)

Lighter shades of gray = higher values with 255 (white)


Arrays of Digital images

Height = number of rows

Width = number of columns

Each pixel (blocks) has its on index like the picture above

  1. Rows start at the top of image and move down

  2. columns start at the left of the image and move right


Combination of Red, Blue, Green images

= This is simply called as RGB images

Color values are represented in different channels.

Each scale is image.

Red channel intensive values, blue channel intensive values, and green channel intensive values

Contrast with gray scale image, it is made up with a square shape but color image is made up with a cube shape

For the color image, each one of these channels has its own intensity values too!!


*Video sequence is a sequence of integer*


Now, how to change images with code (Python)?

The pillow, PIL library is a popular library for working with images in python.


Some examples used in PIL.

1. Import the image module from PIL and create PIL image object

*provided that the name of image is "Lenna"*

image = Image.open(any_image) PIL.pngImagePlugin.pngImageFile

Image.show(title = "Lenna")

Other way to code

import matplotlib.pyplot as plt (defining plt)

plt.imshow(image) (attribute format to the next line)

image.format:PNG (The extension or format of the image)

image.size:(512,512) (attribute size/number if pixels that make up the width and height)

image.mode:RGB (attribute mode/color space/RGB)

2. Convert to the gray-scale

image_gray = ImageOps.grayscale(image)

image_gray.mode:L *L stands Luminance*

image_gray.save("Lenna.jpg") ---------> can convert it from PNG to JPEG




Copyright Coursera All rights reserved




Comments


bottom of page