Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Метод Собеля / Метод Собеля

.doc
Скачиваний:
26
Добавлен:
01.05.2014
Размер:
142.34 Кб
Скачать

Имеется входное изображение. Нужно выделить глаза, нос, рот и контур лица.

I = imread('D:\1.bmp');

figure, imshow(I), title('original image');

Рис. 1

Изменения в контрасте могут быть определены с помощью операторов, которые вычисляют градиент изображения. В свою очередь градиент изображения может быть вычислен и на нём может быть выделена граница для построения бинарной маски. Для начала я использую метод edge и операцию Sobel, для вычисления порогового значения. Затем регулирую пороговое значение и опять использую метод edge для получения бинарной маски.

[junk threshold] = edge(I, 'sobel');

fudgeFactor = .5;

BWs = edge(I,'sobel', threshold * fudgeFactor);

figure, imshow(BWs), title('binary gradient mask');

Рис. 2

Следущий шаг: растягиваем изображение

Бинарная градиентная маска показывает линии контраста в изображении. Эти линии не достаточно чётко обрисовывают границы объекта на изображении. Сравнивая начальное изображение с изображением градиентной маски исходного изображения, видим промежутки на контурах изображения. Это можно исправить с помощью линейного структурирования элементов, с помощью strel function.

se90 = strel('line', 3, 90);

se0 = strel('line', 3, 0);

Бинарная градиентная маска расширяется с помощью вертикально структурированных элементов. Функция imdilate расширяет изображение.

BWsdil = imdilate(BWs, [se90 se0]);

figure, imshow(BWsdil), title('dilated gradient mask');

Рис. 3

Заполняем внутренние промежутки

Расширенная градиентная маска показывает границу достаточно хорошо, но всё же имеются промежутки в контурах, для исправляния этого недостатка мы функцию imfill.

BWdfill = imfill(BWsdil, 'holes');

figure, imshow(BWdfill);

title('binary image with filled holes');

Рис. 4

title('binary image with filled holes');

BWnobord = imclearborder(BWdfill, 4);

figure, imshow(BWnobord), title('cleared border image');

Рис. 5

seD = strel('diamond',1);

BWfinal = imerode(BWnobord,seD);

BWfinal = imerode(BWfinal,seD);

figure, imshow(BWfinal), title('segmented image');

Рис. 6

BWoutline = bwperim(BWfinal);

Segout = I;

Segout(BWoutline) = 255;

figure, imshow(Segout), title('outlined original image');

Рис. 7

EDGE Find edges in intensity image.

EDGE takes an intensity or a binary image I as its input, and returns a

binary image BW of the same size as I, with 1's where the function

finds edges in I and 0's elsewhere.

EDGE supports six different edge-finding methods:

The Sobel method finds edges using the Sobel approximation to the

derivative. It returns edges at those points where the gradient of

I is maximum.

The Prewitt method finds edges using the Prewitt approximation to

the derivative. It returns edges at those points where the gradient

of I is maximum.

The Roberts method finds edges using the Roberts approximation to

the derivative. It returns edges at those points where the gradient

of I is maximum.

The Laplacian of Gaussian method finds edges by looking for zero

crossings after filtering I with a Laplacian of Gaussian filter.

The zero-cross method finds edges by looking for zero crossings

after filtering I with a filter you specify.

The Canny method finds edges by looking for local maxima of the

gradient of I. The gradient is calculated using the derivative of a

Gaussian filter. The method uses two thresholds, to detect strong

and weak edges, and includes the weak edges in the output only if

they are connected to strong edges. This method is therefore less

likely than the others to be "fooled" by noise, and more likely to

detect true weak edges.

The parameters you can supply differ depending on the method you

specify. If you do not specify a method, EDGE uses the Sobel method.

Sobel Method

------------

BW = EDGE(I,'sobel') specifies the Sobel method.

BW = EDGE(I,'sobel',THRESH) specifies the sensitivity threshold for

the Sobel method. EDGE ignores all edges that are not stronger than

THRESH. If you do not specify THRESH, or if THRESH is empty ([]),

EDGE chooses the value automatically.

BW = EDGE(I,'sobel',THRESH,DIRECTION) specifies directionality for the

Sobel method. DIRECTION is a string specifying whether to look for

'horizontal' or 'vertical' edges, or 'both' (the default).

BW = EDGE(I,'sobel',...,OPTIONS) provides an optional string

input. String 'nothinning' speeds up the operation of the algorithm by

skipping the additional edge thinning stage. By default, or when

'thinning' string is specified, the algorithm applies edge thinning.

[BW,thresh] = EDGE(I,'sobel',...) returns the threshold value.

[BW,thresh,gv,gh] = EDGE(I,'sobel',...) returns vertical and

horizontal edge responses to Sobel gradient operators. You can

also use these expressions to obtain gradient responses:

if ~(isa(I,'double') || isa(I,'single')); I = im2single(I); end

gh = imfilter(I,fspecial('sobel') /8,'replicate'); and

gv = imfilter(I,fspecial('sobel')'/8,'replicate');

Литература

  1. Matlab help

  2. http://www.mathworks.com/products/image/demos.html

  3. http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=8031&objectType=file

Соседние файлы в папке Метод Собеля