[Udacity][Computer Vision]Filter & Noise

该系列主要为上Udacity Computer Vision公开课所做的笔记,内容将会涉及一些公开课视频截图,如有侵权请联系删除

Image as A Funciton

Image as A Function

Impulse

面积为1,相当于图片中的基本单位

Correlation vs Convolution

Convolution的结果为Correlation作一次左右翻转再做一次上下翻转。
对于Impulse Image做Filter,Corelation将会得到一个左右、上下翻转后的Filter,而Convolution将会得到Filter本身。
对于对称的Filter,Correlation与Convolution的结果相同

Formula for Correlation and Convolution
Correlation
Convolution

Image Filter

Gaussian Filter

Influence of Sigma

Influence of Sigma in Gaussian Filter

Code

pkg load image;

img = imread('../../resource/sample_img.png');
imshow(img);


%% create a gaussian filter
filter_size = 21;
filter_sigma = 3;
filter = fspecial('gaussian', filter_size, filter_sigma);
smoothed = imfilter(img, filter, 0);

%0
%circular  
%replicate
%symmetric

smoothed = imfilter(img, filter, 'circular');

imshow(smoothed);

Edge Problem

  • clip filter(black) 0
clip filter
  • wrap around Circular
wrap around
  • copy edge Replicate
copy edge
  • reflect across edge Symmetric
    reflect across edge

Unsharp Mask

Unsharp Mask

Salt & Pepper Noise and Median Filter

Salt & Pepper Noise

Salt & Pepper Noise

Median Filter

Median Filter is not linear

Median Filter

Code in Matlab or Octave

noisy_img = imnoise(img, 'salt & pepper', 0.02);
imshow(noisy_img);
%median filter
median_filtered = medfilt2(noisy_img);
imshow(median_filtered);

Filter as Template

2A-L4

Template Matching

从Image中寻找Template

Normalized Correlation

Finding Template
Correlation Map

1-D Case

例如一维信号

onion = [1,2,3,4,5]
peppers = [2,3,4]

其normalized correlation为最大值处就是template所在位置

onion = [1,2,3,4,5]
peppers = [2,3,4]
normxcorr2(onion, peppers);
%-0.86603  -0.50000   1.00000   1.00000   1.00000  -0.50000  -0.86603
%其中结果第一位为
%  2, 3, 4
%        1,2,3,4,5
%第二位
% 2,3,4
%   1,2,3,4,5

2-D Case

function [yIndex xIndex] = find_template_2D(template, img)
    c = normxcorr2(template, img);
    [yRaw xRaw] = find(c == max(c(:)));
    yIndex = yRaw - size(template, 1) + 1;
    xIndex = xRaw - size(template, 2) + 1;
end

Edge Detection

Gradient

Image Gradient

Image Gradient

Gradient Matrix

Gradient Matrix

Well-Known Gradient Mask

Sobel Operator

因为大部分图片都是smooth的,所以在计算gradient时可以使用Sobel Operator

Sobel Operator Matrix

在Matlab中,Sobel Operator function没有系数1/8,因此结果为8倍

filt = fspecial('sobel')
% filt = [[1, 2, 1]; [0,0,0], [-1, -2, -1]];
[gx gy] = imgradientxy(img, 'sobel');
% gx gradient in x direction
% gy gradient in y direction
imshow((gx + 4) / 8);  %normalize
imshow(gx, [-4, 4]);

% magnitude and direction
[gmag, gdir] = imgradient(gx, gy);

Other

Well-Known Gradient Mask

Real World

现实世界中,由于图片一般有noise,所以在计算gradient之前需要先把图片通过filter来smooth。由于derivative和filter都是linear operation,可以使用以下公式

Real World Gradient

先对gradient mask使用filter,再将其apply至图片

filtered before gradient

2nd Derivative

对图片进行2nd Derivative of Gaussian Filter,0点即为Gradient的极值点,即为Edge

2nd Derivate of Gaussian Filter

Effect of Sigma of Gaussian Derivative

Sigma of Gaussian Derivative

Canny Edge Operator

Gradient的结果要成为边缘图,还需要将 Gradient图细化并进行线条连接。这时可以使用Canny Edge Operator。

Canny Edge Operator - 1
Canny Edge Operator -2
Steps
Original Image
Magnitude of The Gradient
Thresholding
Thining
Canny: Non-maximal suppression
Canny threshold hysteresis
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 日子就这样过,每天很痛苦地起床,早自修,早操,上课,下课,中午在食堂吃饭,学生食堂像个蜂窝一样,班里就有人在教师食...
    何青猊阅读 230评论 0 0
  • 生姜性辛,微温,归肺、脾、胃经。能够解表散寒,温中止呕,化痰止咳。用于风寒感冒,胃寒呕吐,寒痰咳嗽。 姜的药用价值...
    飘雪之梦阅读 363评论 0 2
  • 昨日晚上下班回到营地的时候,月光已经洒满整个院子。 同事们已经把餐桌从饭厅搬到了一楼的大厅里,还在餐桌的一头加放了...
    阳光洒落肩膀阅读 163评论 0 0
  • 又是匆匆的毕业季,人们或哭或笑,最后,奔波于天涯海角。人们常说一群人的狂欢,一个人的孤独。可能是认为没有朋友的陪...
    苏月亮阅读 488评论 0 1
  • 目标:养成在家吃完饭的习惯 步骤一:定闹钟。(五分钟内完成)之前没有定闹钟的习惯,所以总是想着早起,没有闹钟约束 ...
    邢哈妮儿阅读 161评论 0 0