Анализ изображений и видео Наталья Васильева [email protected] HP Labs Russia 21 сентября 2012, Computer Science Center Лекция 2: Основы пространственной и частотной обработки изображений
Анализ изображений и видео
Наталья Васильева [email protected] HP Labs Russia
21 сентября 2012, Computer Science Center
Лекция 2: Основы пространственной и частотной обработки изображений
2 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Обработка изображений
Обработка изображений Image Processing
Изображение Изображение
• На входе и выходе – изображения • Результат обработки «лучше» оригинала с точки зрения конкретного применения
• Лучше с эстетической точки зрения • Лучше для последующего анализа
3 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Примеры
4 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Примеры
5 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
План лекции
• Пространственная область • Частотная область, преобразование Фурье • Обработка в пространственной области • Обработка в частотной области
6 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Представление цифровых изображений (recap)
Цветное растровое изображение:
7 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Пространственная область
= + +
= + +
f(x,y)
8 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Представим «одномерную картинку»
0 20 40 60 80 100 120 140 160 180 2000
50
100
150
200
250
300
9 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
1-D изображение
0 50 100 150 200 25020
40
60
80
100
120
140
160
180
200
220
10 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Частотное представление – основная идея
= ∑
11 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Преобразование Фурье для изображений – основная идея
• Любое изображение может быть представлено, как сумма синусов и косинусов различной амплитуды и частоты
• Частоты слагаемых характеризуют изображение:
• Яркость «сильно скачет» на небольших участках изображения – будут преобладать слагаемые с высокими частотами
• Яркость плавно изменяется – будут преобладать низкие частоты
12 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Преобразование Фурье
= + +
f(x) F1*g1(x) F2*g2(x) F3*g3(x)
• Преобразование исходного представления изображения, как функции f(x), в частотное представление – набор Fi
• Преобразование обратимо
13 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Преобразование Фурье
Прямое преобразование Фурье непрерывной фукнции одной переменной f(x):
Обратное преобразование Фурье:
g(x,u)
14 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Двумерный случай
Базисные функции: g(x, y, u, v)
Обратное преобразование:
Прямое преобразование
-1
-0.5
0
0.5
1
15 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Визуализация Фурье-спектра
• Фурье-спектр: набор всех |F(u,v)|
• Визуализация спектра – чем выше значение F(u,v), тем «светлее» точка с координатами (u,v)
• Светлый центр спектра – исходное изображение содержит в основном однородные области, без перепадов яркости
• Светлая периферия спектра – изображение содержит много локальных перепадов яркости
http://www1.idc.ac.il/toky/imageproc-10/lectures/fft_2d.pptx
u=0, v=0 u=1, v=0 u=2, v=0 u=-2, v=0 u=-1, v=0
u=0, v=1 u=1, v=1 u=2, v=1 u=-2, v=1 u=-1, v=1
u=0, v=2 u=1, v=2 u=2, v=2 u=-2, v=2 u=-1, v=2
u=0, v=-1 u=1, v=-1 u=2, v=-1 u=-2, v=-1 u=-1, v=-1
u=0, v=-2 u=1, v=-2 u=2, v=-2 u=-2, v=-2 u=-1, v=-2
U
V
16 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Визуализация Фурье-спектра
f(x,y) F(u,v)
17 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Примеры
18 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Еще примеры
19 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Обработка в пространственной области
• Обработка в пространственной области – манипулирование пикселями изображения
• Например, инвертирование
20 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Гистограммы
0
500
1000
1500
2000
2500
3000
3500
0 50 100 150 200 250
0
500
1000
1500
2000
2500
3000
3500
0 50 100 150 200 250
21 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Гистограммы
0
500
1000
1500
2000
2500
0 50 100 150 200 250
0
500
1000
1500
2000
0 50 100 150 200 250
22 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Гистограммы - коррекция
• Линейное преобразование – линейное «растяжение» гистограммы, устойчивое растяжение
• Нелинейное преобразование • Эквализация (линеаризция) гистограммы
∑∑==
===
−==
k
i
ik
iixkk
kkx
nnxpxfy
Lknnxp
00)()(
1,..,1,0,)(
23 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Результат эквализации гистограммы
0
500
1000
1500
2000
0 50 100 150 200 250
0
500
1000
1500
2000
2500
3000
3500
0 50 100 150 200 250
0
500
1000
1500
2000
2500
3000
3500
0 50 100 150 200 250
0
500
1000
1500
2000
0 50 100 150 200 250
24 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Результат эквализации гистограммы
0
500
1000
1500
2000
2500
0 50 100 150 200 250
0
200
400
600
800
1000
1200
1400
1600
1800
2000
0 50 100 150 200 250
0
500
1000
1500
2000
0 50 100 150 200 250
0
200
400
600
800
1000
1200
1400
1600
1800
2000
0 50 100 150 200 250
25 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Пороговая бинаризация
Светлый объект на темном фоне
Два светлых объекта на темном фоне
Глобальная – порог единый для всех точек изображения Локальная или Динамическая – когда порог зависит от координат точки (x,y) Адаптивная – когда порог зависит от значения яркости в точке I(x,y)
26 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Глобальная бинаризация
• Выбор порога вручную
• Выбор порога автоматически 1. Случайно выбрать начальное значение порога T0 2. Сегментировать изображение по порогу T0: регионы
G1 и G2 из пикселей со значениями >T0 и ≤ T0 3. Вычислить средние значения µ1 and µ2 для регионов
G1 and G2 4. T1 = 0.5 (µ1 + µ2) 5. Повторять пока | Ti - Ti+1|< Tth
27 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Примеры бинаризации
28 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Выделение компонент связности
0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0 0 0 0 0 0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0
0
0 0 0
0 0 0
0 0 0
0 0 0 0 0 0
0 0 0 0 0
1 1
1 1 1 1 1 1 1 1
1 1 1 1
1 1 1 1
1 1 1
1 1
1 1
2 2 3 3
3 3
3 3
4 4
3 3 3 3
3 3 3 3
3 3 3
3 3 3
5 3
5 3 6 6 3 3 3 7
0
29 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Компоненты связности
30 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Фильтрация (свертка изображения с фильтром)
Операция свертки:
f – изображение w – ядро, фильтр g – результат свертки f*w
Свойства: • коммутативность: f*w = w*f • ассоциативность: f*(w1*w2)=(f*w1)*w2 • дистрибутивность по сложению: f*(w1+w2=f*w1 + f*w2 • kf*w = f*kw = k(f*w)
31 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Теорема о свертке
g = f * h g = f h
implies implies
G = F H G = F * H
Slide: http://www1.idc.ac.il/toky/imageproc-10/lectures/fft_2d.pptx
32 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Теорема о свертке
Problem in Frequency
Space
Original Problem
Solution in Frequency
Space
Solution of Original Problem
Relatively easy solution
Difficult solution
Fourier Transform
Inverse Fourier Transform
Slide: http://www1.idc.ac.il/toky/imageproc-10/lectures/fft_2d.pptx
33 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Сглаживание
• Линейные усредняющие фильтры – удаление «случайного шума»
• Фильтры, основанные на порядковых статистиках • Медианный фильтр (подавление шума «соль и перец»)
34 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Сглаживание фильтром Гаусса
Свертка с ядром Гаусса
35 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Сглаживание фильтром Гаусса: пример
Sigma =1.4 Size = 5
Sigma =2.8 Size = 10
36 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Выделение деталей
A point has been detected if |g| ≥ T, • T is a nonnegative threshold
37 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Обнаружение линий
• If |gi| > |gj| for all j≠i – the point is within line i. • Use one mask to detect lines of a given direction
38 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Выделение границ: примеры
Sobel Canny Исходное
39 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Обнаружение границ
40 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Градиент изображения Градиент направлен в сторону наибольшего изменения интенсивности
Направление градиента:
Величина градиента:
41 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Вычисление градиента изображения
Roberts: Prewitt: Sobel:
Дискретный случай:
42 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Пример
43 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Обнаружение контуров: вычисление производных
Вычисление второй производной: Лапласиан
•Маски Лапласиана:
2
2
2
22 ),(),(
yyxf
xyxff
∂∂
+∂
∂=∇
44 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Слайд: А. Конушин
45 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Слайд: А. Конушин
46 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Mexican hat
47 © Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Заключение
• Пространственная область • Частотная область, преобразование Фурье, теорема о свертке
• Обработка в пространственной и частотной областях • Гистограммы, бинаризация, выделение связных компонент, сглаживание, повышение резкости, выделение контуров