Image restoration IMAGE P ROCES S IN G IN P YTH ON Rebeca Gonzalez - - PowerPoint PPT Presentation

image restoration
SMART_READER_LITE
LIVE PREVIEW

Image restoration IMAGE P ROCES S IN G IN P YTH ON Rebeca Gonzalez - - PowerPoint PPT Presentation

Image restoration IMAGE P ROCES S IN G IN P YTH ON Rebeca Gonzalez Data Engineer Restore an image IMAGE PROCESSING IN PYTHON Image reconstruction Fixing damaged images T ext removing Logo removing Object removing IMAGE PROCESSING IN


slide-1
SLIDE 1

Image restoration

IMAGE P ROCES S IN G IN P YTH ON

Rebeca Gonzalez

Data Engineer

slide-2
SLIDE 2

IMAGE PROCESSING IN PYTHON

Restore an image

slide-3
SLIDE 3

IMAGE PROCESSING IN PYTHON

Image reconstruction

Fixing damaged images T ext removing Logo removing Object removing

slide-4
SLIDE 4

IMAGE PROCESSING IN PYTHON

Image reconstruction

Inpainting

Reconstructing lost parts of images Looking at the non-damaged regions

slide-5
SLIDE 5

IMAGE PROCESSING IN PYTHON

Image reconstruction

slide-6
SLIDE 6

IMAGE PROCESSING IN PYTHON

Image reconstruction in scikit-image

from skimage.restoration import inpaint # Obtain the mask mask = get_mask(defect_image) # Apply inpainting to the damaged image using the mask restored_image = inpaint.inpaint_biharmonic(defect_image, mask, multichannel=True) # Show the resulting image show_image(restored_image)

slide-7
SLIDE 7

IMAGE PROCESSING IN PYTHON

Image reconstruction in scikit-image

# Show the defect and resulting images show_image(defect_image, 'Image to restore') show_image(restored_image, 'Image restored')

slide-8
SLIDE 8

IMAGE PROCESSING IN PYTHON

Masks

slide-9
SLIDE 9

IMAGE PROCESSING IN PYTHON

Masks

def get_mask(image): ''' Creates mask with three defect regions ''' mask = np.zeros(image.shape[:-1]) mask[101:106, 0:240] = 1 mask[152:154, 0:60] = 1 mask[153:155, 60:100] = 1 mask[154:156, 100:120] = 1 mask[155:156, 120:140] = 1 mask[212:217, 0:150] = 1 mask[217:222, 150:256] = 1 return mask

slide-10
SLIDE 10

Let's practice!

IMAGE P ROCES S IN G IN P YTH ON

slide-11
SLIDE 11

Noise

IMAGE P ROCES S IN G IN P YTH ON

Rebeca Gonzalez

Data Engineer

slide-12
SLIDE 12

IMAGE PROCESSING IN PYTHON

Noise

slide-13
SLIDE 13

IMAGE PROCESSING IN PYTHON

Noise

slide-14
SLIDE 14

IMAGE PROCESSING IN PYTHON

Apply noise in scikit-image

# Import the module and function from skimage.util import random_noise # Add noise to the image noisy_image = random_noise(dog_image) # Show original and resulting image show_image(dog_image) show_image(noisy_image, 'Noisy image')

slide-15
SLIDE 15

IMAGE PROCESSING IN PYTHON

Apply noise in scikit-image

slide-16
SLIDE 16

IMAGE PROCESSING IN PYTHON

Reducing noise

slide-17
SLIDE 17

IMAGE PROCESSING IN PYTHON

Denoising types

T

  • tal variation (TV)

Bilateral Wavelet denoising Non-local means denoising

slide-18
SLIDE 18

IMAGE PROCESSING IN PYTHON

Denoising

Using total variation lter denoising

from skimage.restoration import denoise_tv_chambolle # Apply total variation filter denoising denoised_image = denoise_tv_chambolle(noisy_image, weight=0.1, multichannel=True) # Show denoised image show_image(noisy_image, 'Noisy image') show_image(denoised_image, 'Denoised image')

slide-19
SLIDE 19

IMAGE PROCESSING IN PYTHON

Denoising

Total variation lter

slide-20
SLIDE 20

IMAGE PROCESSING IN PYTHON

Denoising

Bilateral lter

from skimage.restoration import denoise_bilateral # Apply bilateral filter denoising denoised_image = denoise_bilateral(noisy_image, multichannel=True) # Show original and resulting images show_image(noisy_image, 'Noisy image') show_image(denoised_image, 'Denoised image')

slide-21
SLIDE 21

IMAGE PROCESSING IN PYTHON

Denoising

Bilateral lter

slide-22
SLIDE 22

Let's practice!

IMAGE P ROCES S IN G IN P YTH ON

slide-23
SLIDE 23

Superpixels & segmentation

IMAGE P ROCES S IN G IN P YTH ON

Rebeca Gonzalez

Data Engineer

slide-24
SLIDE 24

IMAGE PROCESSING IN PYTHON

Segmentation

slide-25
SLIDE 25

IMAGE PROCESSING IN PYTHON

Segmentation

slide-26
SLIDE 26

IMAGE PROCESSING IN PYTHON

Image representation

slide-27
SLIDE 27

IMAGE PROCESSING IN PYTHON

Superpixels

slide-28
SLIDE 28

IMAGE PROCESSING IN PYTHON

Benets of superpixels

More meaningful regions Computational efciency

slide-29
SLIDE 29

IMAGE PROCESSING IN PYTHON

Segmentation

Supervised Unsupervised

slide-30
SLIDE 30

IMAGE PROCESSING IN PYTHON

Unsupervised segmentation

Simple Linear Iterative Clustering (SLIC)

slide-31
SLIDE 31

IMAGE PROCESSING IN PYTHON

Unsupervised segmentation (SLIC)

# Import the modules from skimage.segmentation import slic from skimage.color import label2rgb # Obtain the segments segments = segmentation.slic(image) # Put segments on top of original image to compare segmented_image = label2rgb(segments, image, kind='avg') show_image(image) show_image(segmented_image, "Segmented image")

slide-32
SLIDE 32

IMAGE PROCESSING IN PYTHON

Unsupervised segmentation (SLIC)

slide-33
SLIDE 33

IMAGE PROCESSING IN PYTHON

More segments

# Import the modules from skimage.segmentation import slic from skimage.color import label2rgb # Obtain the segmentation with 300 regions segments = slic(image, n_segments= 300) # Put segments on top of original image to compare segmented_image = label2rgb(segments, image, kind='avg') show_image(segmented_image)

slide-34
SLIDE 34

IMAGE PROCESSING IN PYTHON

More segments

slide-35
SLIDE 35

Let's practice!

IMAGE P ROCES S IN G IN P YTH ON

slide-36
SLIDE 36

Finding contours

IMAGE P ROCES S IN G IN P YTH ON

Rebeca Gonzalez

Data Engineer

slide-37
SLIDE 37

IMAGE PROCESSING IN PYTHON

Finding contours

Measure size Classify shapes Determine the number of objects T

  • tal points in domino tokens: 35.
slide-38
SLIDE 38

IMAGE PROCESSING IN PYTHON

Binary images

We can obtain a binary image applying thresholding or using edge detection

slide-39
SLIDE 39

IMAGE PROCESSING IN PYTHON

Find contours using scikit-image

PREPARING THE IMAGE Transform the image to 2D grayscale.

# Make the image grayscale image = color.rgb2gray(image)

slide-40
SLIDE 40

IMAGE PROCESSING IN PYTHON

Find contours using scikit-image

PREPARING THE IMAGE Binarize the image

# Obtain the thresh value thresh = threshold_otsu(image) # Apply thresholding thresholded_image = image > thresh

slide-41
SLIDE 41

IMAGE PROCESSING IN PYTHON

Find contours using scikit-image

And then use find_contours() .

# Import the measure module from skimage import measure # Find contours at a constant value of 0.8 contours = measure.find_contours(thresholded_image, 0.8)

slide-42
SLIDE 42

IMAGE PROCESSING IN PYTHON

Constant level value

slide-43
SLIDE 43

IMAGE PROCESSING IN PYTHON

The steps to spotting contours

from skimage import measure from skimage.filters import threshold_otsu # Make the image grayscale image = color.rgb2gray(image) # Obtain the optimal thresh value of the image thresh = threshold_otsu(image) # Apply thresholding and obtain binary image thresholded_image = image > thresh # Find contours at a constant value of 0.8 contours = measure.find_contours(thresholded_image, 0.8)

slide-44
SLIDE 44

IMAGE PROCESSING IN PYTHON

The steps to spotting contours

Resulting in

slide-45
SLIDE 45

IMAGE PROCESSING IN PYTHON

A contour's shape

Contours: list of (n,2) - ndarrays.

for contour in contours: print(contour.shape) (433, 2) (433, 2) (401, 2) (401, 2) (123, 2) (123, 2) (59, 2) (59, 2) (59, 2) (57, 2) (57 2)

slide-46
SLIDE 46

IMAGE PROCESSING IN PYTHON

A contour's shape

for contour in contours: print(contour.shape) (433, 2) (433, 2) --> Outer border (401, 2) (401, 2) (123, 2) (123, 2) (59, 2) (59, 2) (59, 2) (57, 2) (57, 2) (59, 2) (59, 2)

slide-47
SLIDE 47

IMAGE PROCESSING IN PYTHON

A contour's shape

for contour in contours: print(contour.shape) (433, 2) (433, 2) --> Outer border (401, 2) (401, 2) --> Inner border (123, 2) (123, 2) (59, 2) (59, 2) (59, 2) (57, 2) (57, 2) (59, 2) (59, 2)

slide-48
SLIDE 48

IMAGE PROCESSING IN PYTHON

A contour's shape

for contour in contours: print(contour.shape) (433, 2) (433, 2) --> Outer border (401, 2) (401, 2) --> Inner border (123, 2) (123, 2) --> Divisory line of tokens (59, 2) (59, 2) (59, 2) (57, 2) (57, 2) (59, 2) (59, 2)

slide-49
SLIDE 49

IMAGE PROCESSING IN PYTHON

A contour's shape

for contour in contours: print(contour.shape) (433, 2) (433, 2) --> Outer border (401, 2) (401, 2) --> Inner border (123, 2) (123, 2) --> Divisory line of tokens (59, 2) (59, 2) (59, 2) (57, 2) (57, 2) (59, 2) (59, 2) --> Dots

Number of dots: 7.

slide-50
SLIDE 50

Let's practice!

IMAGE P ROCES S IN G IN P YTH ON