Make images come alive with scikit- image IMAGE P ROCES S IN G IN - - PowerPoint PPT Presentation

make images come alive with scikit image
SMART_READER_LITE
LIVE PREVIEW

Make images come alive with scikit- image IMAGE P ROCES S IN G IN - - PowerPoint PPT Presentation

Make images come alive with scikit- image IMAGE P ROCES S IN G IN P YTH ON Rebeca Gonzalez Data Engineer What is image processing? Operations on images and videos to: Enhance an image Extract useful information Analyze it and make


slide-1
SLIDE 1

Make images come alive with scikit- image

IMAGE P ROCES S IN G IN P YTH ON

Rebeca Gonzalez

Data Engineer

slide-2
SLIDE 2

IMAGE PROCESSING IN PYTHON

What is image processing?

Operations on images and videos to: Enhance an image Extract useful information Analyze it and make decisions

slide-3
SLIDE 3

IMAGE PROCESSING IN PYTHON

What is image processing?

Operations to on images and videos to: Enhance an image Extract useful information Analyze it and make decisions

slide-4
SLIDE 4

IMAGE PROCESSING IN PYTHON

Applications

Medical image analysis Articial intelligence Image restoration and enhancement Geospatial computing Surveillance Robotic vision Automotive safety And many more...

slide-5
SLIDE 5

IMAGE PROCESSING IN PYTHON

Purposes

  • 1. Visualization:

Objects that are not visible

  • 2. Image sharpening and restoration

A better image

  • 3. Image retrieval

Seek for the image of interest

  • 4. Measurement of pattern

Measures various objects

  • 5. Image Recognition

Distinguish objects in an image

slide-6
SLIDE 6

IMAGE PROCESSING IN PYTHON

Intro to scikit-image

Easy to use Makes use of Machine Learning Out of the box complex algorithms

slide-7
SLIDE 7

IMAGE PROCESSING IN PYTHON

What is an image?

slide-8
SLIDE 8

IMAGE PROCESSING IN PYTHON

What is an image?

slide-9
SLIDE 9

IMAGE PROCESSING IN PYTHON

Images in scikit-image

from skimage import data rocket_image = data.rocket()

slide-10
SLIDE 10

IMAGE PROCESSING IN PYTHON

RGB channels

slide-11
SLIDE 11

IMAGE PROCESSING IN PYTHON

Grayscaled images

slide-12
SLIDE 12

IMAGE PROCESSING IN PYTHON

RGB vs Grayscale

from skimage import color grayscale = color.rgb2gray(original) rgb = color.gray2rgb(grayscale)

slide-13
SLIDE 13

IMAGE PROCESSING IN PYTHON

Visualizing images in the course

Don't worry about Matplotlib!

def show_image(image, title='Image', cmap_type='gray'): plt.imshow(image, cmap=cmap_type) plt.title(title) plt.axis('off') plt.show()

slide-14
SLIDE 14

IMAGE PROCESSING IN PYTHON

Visualizing images in the course

from skimage import color grayscale = color.rgb2gray(original) show_image(grayscale, "Grayscale")

slide-15
SLIDE 15

Let's practice!

IMAGE P ROCES S IN G IN P YTH ON

slide-16
SLIDE 16

NumPy for images

IMAGE P ROCES S IN G IN P YTH ON

Rebeca Gonzalez

Data Engineer

slide-17
SLIDE 17

IMAGE PROCESSING IN PYTHON

NumPy for images

Fundamentals of image processing techniques Flipping Extract and analyze features

slide-18
SLIDE 18

IMAGE PROCESSING IN PYTHON

Images as NdArrays

# Loading the image using Matplotlib madrid_image = plt.imread('/madrid.jpeg') type(madrid_image) <class 'numpy.ndarray'>

slide-19
SLIDE 19

IMAGE PROCESSING IN PYTHON

Colors with NumPy

slide-20
SLIDE 20

IMAGE PROCESSING IN PYTHON

Colors with NumPy

# Obtaining the red values of the image red = image[:, :, 0] # Obtaining the green values of the image green = image[:, :, 1] # Obtaining the blue values of the image blue = image[:, :, 2]

slide-21
SLIDE 21

IMAGE PROCESSING IN PYTHON

Colors with NumPy

plt.imshow(red, cmap="gray") plt.title('Red') plt.axis('off') plt.show()

slide-22
SLIDE 22

IMAGE PROCESSING IN PYTHON

Shapes

# Accessing the shape of the image madrid_image.shape (426, 640, 3)

slide-23
SLIDE 23

IMAGE PROCESSING IN PYTHON

Sizes

# Accessing the shape of the image madrid_image.size 817920

slide-24
SLIDE 24

IMAGE PROCESSING IN PYTHON

Flipping images: vertically

# Flip the image in up direction vertically_flipped = np.flipud(madrid_image) show_image(vertically_flipped, 'Vertically flipped image')

slide-25
SLIDE 25

IMAGE PROCESSING IN PYTHON

Flipping images: horizontally

# Flip the image in left direction horizontally_flipped = np.fliplr(madrid_image) show_image(horizontally_flipped, 'Horizontally flipped image')

slide-26
SLIDE 26

IMAGE PROCESSING IN PYTHON

What is a histogram?

slide-27
SLIDE 27

IMAGE PROCESSING IN PYTHON

Color histograms

slide-28
SLIDE 28

IMAGE PROCESSING IN PYTHON

Applications of histograms

Analysis Thresholding Brightness and contrast Equalize an image

slide-29
SLIDE 29

IMAGE PROCESSING IN PYTHON

Histograms in Matplotlib

# Red color of the image red = image[:, :, 0] # Obtain the red histogram plot.hist(red.ravel(), bins=256)

slide-30
SLIDE 30

IMAGE PROCESSING IN PYTHON

Visualizing histograms with Matplotlib

blue = image[:, :, 2] plt.hist(blue.ravel(), bins=256) plt.title('Blue Histogram') plt.show()

slide-31
SLIDE 31

Let's practice!

IMAGE P ROCES S IN G IN P YTH ON

slide-32
SLIDE 32

Getting started with thresholding

IMAGE P ROCES S IN G IN P YTH ON

Rebeca Gonzalez

Data Engineer

slide-33
SLIDE 33

IMAGE PROCESSING IN PYTHON

Thresholding

Partitioning an image into a foreground and background By making it black and white We do so by setting each pixel to: 255 (white) if pixel > thresh value 0 (black) if pixel < thresh value

slide-34
SLIDE 34

IMAGE PROCESSING IN PYTHON

Thresholding

Simplest method of image segmentation Isolate objects Object detection Face detection Etc.

slide-35
SLIDE 35

IMAGE PROCESSING IN PYTHON

Thresholding

Only from grayscale images

slide-36
SLIDE 36

IMAGE PROCESSING IN PYTHON

Apply it

# Obtain the optimal threshold value thresh = 127 # Apply thresholding to the image binary = image > thresh # Show the original and thresholded show_image(image, 'Original') show_image(binary, 'Thresholded')

slide-37
SLIDE 37

IMAGE PROCESSING IN PYTHON

Inverted thresholding

# Obtain the optimal threshold value thresh = 127 # Apply thresholding to the image inverted_binary = image <= thresh # Show the original and thresholded show_image(image, 'Original') show_image(inverted_binary, 'Inverted thresholded')

slide-38
SLIDE 38

IMAGE PROCESSING IN PYTHON

Categories

Global or histogram based: good for uniform backgrounds Local or adaptive: for uneven background illumination

slide-39
SLIDE 39

IMAGE PROCESSING IN PYTHON

Try more thresholding algorithms

from skimage.filters import try_all_threshold # Obtain all the resulting images fig, ax = try_all_threshold(image, verbose=False) # Showing resulting plots show_plot(fig, ax)

slide-40
SLIDE 40

IMAGE PROCESSING IN PYTHON

Try more thresholding algorithms

slide-41
SLIDE 41

IMAGE PROCESSING IN PYTHON

Optimal thresh value

Global

Uniform background

# Import the otsu threshold function from skimage.filters import threshold_otsu # Obtain the optimal threshold value thresh = threshold_otsu(image) # Apply thresholding to the image binary_global = image > thresh

slide-42
SLIDE 42

IMAGE PROCESSING IN PYTHON

Optimal thresh value

Global

# Show the original and binarized image show_image(image, 'Original') show_image(binary_global, 'Global thresholding')

slide-43
SLIDE 43

IMAGE PROCESSING IN PYTHON

Optimal thresh value

Local

Uneven background

# Import the local threshold function from skimage.filters import threshold_local # Set the block size to 35 block_size = 35 # Obtain the optimal local thresholding local_thresh = threshold_local(text_image, block_size, offset=10) # Apply local thresholding and obtain the binary image binary_local = text_image > local_thresh

slide-44
SLIDE 44

IMAGE PROCESSING IN PYTHON

Optimal thresh value

Local

# Show the original and binarized image show_image(image, 'Original') show_image(binary_local, 'Local thresholding')

slide-45
SLIDE 45

Let's practice!

IMAGE P ROCES S IN G IN P YTH ON