open cv+C++错误及经验总结(五)

Smoothing images------linear filter

smoothing, also called blurring, is a simple and frequently used image processing operation. 

nothing more than 仅仅,只不过

normalized box filter 归一化滤波

  • This filter is the simplest of all! Each output pixel is the mean of its kernel neighbors ( all of them contribute with equal weights)

  • The kernel is below:

    K = \dfrac{1}{K_{width} \cdot K_{height}} \begin{bmatrix}    1 & 1 & 1 & ... & 1 \\    1 & 1 & 1 & ... & 1 \\    . & . & . & ... & 1 \\    . & . & . & ... & 1 \\    1 & 1 & 1 & ... & 1   \end{bmatrix}

Gaussian filter 高斯滤波

  • Probably the most useful filter (although not the fastest). Gaussian filtering is done by convolving each point in the input array with a Gaussian kernel and then summing them all to produce the output array.

  • Just to make the picture clearer, remember how a 1D Gaussian kernel look like?

    ../../../../_images/Smoothing_Tutorial_theory_gaussian_0.jpg

    Assuming that an image is 1D, you can notice that the pixel located in the middle would have the biggest weight. The weight of its neighbors decreases as the spatial distance between them and the center pixel increases.

Note

 

Remember that a 2D Gaussian can be represented as :

G_{0}(x, y) = A  e^{ \dfrac{ -(x - \mu_{x})^{2} }{ 2\sigma^{2}_{x} } +  \dfrac{ -(y - \mu_{y})^{2} }{ 2\sigma^{2}_{y} } }

where \mu is the mean (the peak) and \sigma represents the variance (per each of the variables x and y)

median filter 中值滤波

The median filter run through each element of the signal (in this case the image) and replace each pixel with the median of its neighboring pixels (located in a square neighborhood around the evaluated pixel).

Eroding and Dilating

Goal:In this tutorial you will learn how to:

Apply two very common morphology operators:Dilation and Erosion.for this purpose,you will use the following Opencv functions:

Erode腐蚀

dilate膨胀

isolation

生词本
去背诵
英 [ˌaɪsəˈleɪʃn]
美 [ˌaɪsəˈleʃən]

n.   

adj. 

morphological

生词本
英 [ˌmɔ:fə'lɒdʒɪkl]
美 [ˌmɔ:fə'lɒdʒɪkl]

adj.

morphology

生词本
英 [mɔ:ˈfɒlədʒi]
美 [mɔrˈfɑlədʒi]

n.

Morphological Operations

  • In short: A set of operations that process images based on shapes. Morphological operations apply astructuring element to an input image and generate an output image.

  • The most basic morphological operations are two: Erosion and Dilation. They have a wide array of uses, i.e. :

    • Removing noise
    • Isolation of individual elements and joiningdisparate elements in an image.
    • Finding of intensity bumps or holes in an image寻找图像中的明显的极大值区域或极小值区域。
  • We will explain dilation and erosion briefly, using the following image as an example:

dilation

生词本
英 [daɪ'leɪʃn]
美 [daɪ'leɪʃn]

n.

英 [ɪ'rəʊʒn]
美 [ɪˈrəʊʒ(ə)n]

n.   

anchor point

生词本
英 [ˈæŋkə pɔint]
美 [ˈæŋkɚ pɔɪnt]

n.

analogously

生词本
英 [ə'næləgəslɪ] 美 [ə'næləgəslɪ]

adv.Dilation

  • This operations consists of convoluting an image A with some kernel (B), which can have any shape or size, usually a square or circle.

  • The kernel B has a defined anchor point, usually being the center of the kernel.

  • As the kernel B is scanned over the image, we compute the maximal pixel value overlapped by B and replace the image pixel in the anchor point position with that maximal value. As you can deduce, this maximizing operation causes bright regions within an image to “grow” (therefore the name dilation). Take as an example the image above. Applying dilation we can get:

    Dilation result - Theory example

The background (bright) dilates around the black regions of the letter.背景(白色)膨胀,而黑色字母缩小了。


Erosion
  • This operation is the sister of dilation. What this does is to compute a local minimum over the area of the kernel.

  • As the kernel B is scanned over the image, we compute the minimal pixel value overlapped by B and replace the image pixel under the anchor point with that minimal value.

  • Analagously to the example for dilation, we can apply the erosion operator to the original image (shown above). You can see in the result below that the bright areas of the image (the background, apparently), get thinner, whereas the dark zones (the “writing”( gets bigger.


Morphological Gradient   形态梯度

top hat高帽  black hat黑帽

sophisticated

生词本
去背诵
英 [səˈfɪstɪkeɪtɪd]
美 [səˈfɪstɪˌketɪd]

adj.   

v.  

effectuate

生词本
英 [ɪ'fektʃʊeɪt]
美 [ɪ'fektʃʊeɪt]

vt.

trackbar表示一个标准的windows跟踪条

getStructuringElement

Returns a structuring element of the specified size and shape for morphological operations.

C++:  Mat  getStructuringElement (int  shape, Size  ksize, Point  anchor=Point(-1,-1) )
Python:   cv2. getStructuringElement (shape, ksize [, anchor ] ) → retval
C:  IplConvKernel*  cvCreateStructuringElementEx (int  cols, int  rows, int  anchorX, int  anchorY, int  shape, int*  values=NULL  )
Python:   cv. CreateStructuringElementEx (cols, rows, anchorX, anchorY, shape, values=None ) → kernel
Parameters:
  • shape –

    Element shape that could be one of the following:

    • MORPH_RECT - a rectangular structuring element:

      E_{ij}=1

    • MORPH_ELLIPSE - an elliptic structuring element, that is, a filled ellipse inscribed into the rectangle Rect(0,0, esize.width, 0.esize.height)
    • MORPH_CROSS - a cross-shaped structuring element:

      E_{ij} =  \fork{1}{if i=\texttt{anchor.y} or j=\texttt{anchor.x}}{0}{otherwise}

    • CV_SHAPE_CUSTOM - custom structuring element (OpenCV 1.x API)
  • ksize – Size of the structuring element.
  • cols – Width of the structuring element
  • rows – Height of the structuring element
  • anchor – Anchor position within the element. The default value (-1, -1) means that the anchor is at the center. Note that only the shape of a cross-shaped element depends on the anchor position. In other cases the anchor just regulates how much the result of the morphological operation is shifted.
  • anchorX – x-coordinate of the anchor
  • anchorY – y-coordinate of the anchor
  • values – integer array of cols``*``rows elements that specifies the custom shape of the structuring element, whenshape=CV_SHAPE_CUSTOM.

The function constructs and returns the structuring element that can be further passed to createMorphologyFilter()erode()dilate()or morphologyEx() . But you can also construct an arbitrary binary mask yourself and use it as the structuring element.

Note

 

When using OpenCV 1.x C API, the created structuring element IplConvKernel* element must be released in the end usingcvReleaseStructuringElement(&element).

createTrackbar

Creates a trackbar and attaches it to the specified window.

C++:  int  createTrackbar (const string&  trackbarname, const string&  winname, int*  value, int  count, TrackbarCallback  onChange=0, void*  userdata=0 )
C:  int  cvCreateTrackbar (const char*  trackbarName, const char*  windowName, int*  value, int  count, CvTrackbarCallback  onChange )
Python:   cv. CreateTrackbar (trackbarName, windowName, value, count, onChange ) → None
Parameters:
  • trackbarname – Name of the created trackbar.
  • winname – Name of the window that will be used as a parent of the created trackbar.
  • value – Optional pointer to an integer variable whose value reflects the position of the slider. Upon creation, the slider position is defined by this variable.
  • count – Maximal position of the slider. The minimal position is always 0.
  • onChange – Pointer to the function to be called every time the slider changes position. This function should be prototyped as void Foo(int,void*); , where the first parameter is the trackbar position and the second parameter is the user data (see the next parameter). If the callback is the NULL pointer, no callbacks are called, but only valueis updated.
  • userdata – User data that is passed as is to the callback. It can be used to handle trackbar events without using global variables.

The function createTrackbar creates a trackbar (a slider or range control) with the specified name and range, assigns a variable value to be a position syncronized with the trackbar and specifies the callback function onChange to be called on the trackbar position change. The created trackbar is displayed in the specified window winname.

Note

 

[Qt Backend Only] winname can be empty (or NULL) if the trackbar should be attached to the control panel.

Clicking the label of each trackbar enables editing the trackbar values manually.

pyramids

生词本
去背诵
[ˈpirəmidz]

n.   

upsampling 采样

英 [ɪn'dʒekt]
美 [ɪnˈdʒɛkt]

vt.   

英 ['ri:dʒekt]
美 [rɪˈdʒɛkt]

vt.   

n.

downsample

网 络
  • 降低采样;
  • 降低取样;
  • 缩小取样

Image Pyramids

Use the OpenCV functions  pyrUp  and  pyrDown  to downsample or upsample a given image.

如何使用OpenCV函数 pyrUp 和 pyrDown 对图像进行向上和向下采样。

Although there is a geometric transformation function in OpenCV that -literally- resize an image 

尽管OpenCV 几何变换 部分提供了一个真正意义上的图像缩放函数

literally

生词本
去背诵
英 [ˈlɪtərəli]
美 [ˈlɪtərəli]

adv.   

An image pyramid is a collection of images - all arising from a single original image - that are successively downsampled until some desired stopping point is reached.

一个图像金字塔是一系列图像的集合 - 所有图像来源于同一张原始图像 - 通过梯次向下采样获得,直到达到某个终止条件才停止采样。

Used to reconstruct an upsampled image from an image lower in the pyramid (with less resolution)

用来从金字塔低层图像重建上层未采样图像

Imagine the pyramid as a set of layers in which the higher the layer, the smaller the size.

想想金字塔为一层一层的图像,层级越高,图像越小。

predecessor

生词本
去背诵
英 [ˈpri:dɪsesə(r)]
美 [ˈprɛdɪˌsɛsɚ, ˈpridɪ-]

n.  

iterating

生词本
英 [ɪtə'reɪtɪŋ] 美 [ɪtə'reɪtɪŋ]

v. 

英 [ɪn'taɪə(r)]
美 [ɛnˈtaɪr]

adj.   

英 [wɪt]
美 [wɪt]

n.   

approximate

生词本
去背诵
英 [ə'prɒksɪmət]
美 [əˈprɑksəmɪt]

adj.  

vi. 

vt.  

procedure

生词本
去背诵
英 [prəˈsi:dʒə(r)]
美 [prəˈsidʒɚ]

n.   

semaphore

生词本
英 ['seməfɔ:(r)]
美 [ˈsɛməˌfɔr, -ˌfor]

n.

vt.& vi.



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值