init - 初始化项目
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
Histogram - 3 : Histogram Backprojection {#tutorial_js_histogram_backprojection}
|
||||
========================================
|
||||
|
||||
Goal
|
||||
----
|
||||
|
||||
- We will learn about histogram backprojection.
|
||||
|
||||
Theory
|
||||
------
|
||||
|
||||
It was proposed by **Michael J. Swain , Dana H. Ballard** in their paper **Indexing via color
|
||||
histograms**.
|
||||
|
||||
**What is it actually in simple words?** It is used for image segmentation or finding objects of
|
||||
interest in an image. In simple words, it creates an image of the same size (but single channel) as
|
||||
that of our input image, where each pixel corresponds to the probability of that pixel belonging to
|
||||
our object. In more simpler worlds, the output image will have our object of interest in more white
|
||||
compared to remaining part. Well, that is an intuitive explanation. (I can't make it more simpler).
|
||||
Histogram Backprojection is used with camshift algorithm etc.
|
||||
|
||||
**How do we do it ?** We create a histogram of an image containing our object of interest (in our
|
||||
case, the ground, leaving player and other things). The object should fill the image as far as
|
||||
possible for better results. And a color histogram is preferred over grayscale histogram, because
|
||||
color of the object is a better way to define the object than its grayscale intensity. We then
|
||||
"back-project" this histogram over our test image where we need to find the object, ie in other
|
||||
words, we calculate the probability of every pixel belonging to the ground and show it. The
|
||||
resulting output on proper thresholding gives us the ground alone.
|
||||
|
||||
Backprojection in OpenCV
|
||||
------------------------
|
||||
|
||||
We use the functions: **cv.calcBackProject (images, channels, hist, dst, ranges, scale)**
|
||||
|
||||
@param images source arrays. They all should have the same depth, cv.CV_8U, cv.CV_16U or cv.CV_32F , and the same size. Each of them can have an arbitrary number of channels.
|
||||
@param channels the list of channels used to compute the back projection. The number of channels must match the histogram dimensionality.
|
||||
@param hist input histogram that can be dense or sparse.
|
||||
@param dst destination back projection array that is a single-channel array of the same size and depth as images[0].
|
||||
@param ranges array of arrays of the histogram bin boundaries in each dimension(see cv.calcHist).
|
||||
@param scale optional scale factor for the output back projection.
|
||||
|
||||
**cv.normalize (src, dst, alpha = 1, beta = 0, norm_type = cv.NORM_L2, dtype = -1, mask = new cv.Mat())**
|
||||
|
||||
@param src input array.
|
||||
@param dst output array of the same size as src .
|
||||
@param alpha norm value to normalize to or the lower range boundary in case of the range normalization.
|
||||
@param beta upper range boundary in case of the range normalization; it is not used for the norm normalization.
|
||||
@param norm_type normalization type (see cv.NormTypes).
|
||||
@param dtype when negative, the output array has the same type as src; otherwise, it has the same number of channels as src and the depth = CV_MAT_DEPTH(dtype).
|
||||
@param mask optional operation mask.
|
||||
|
||||
Try it
|
||||
------
|
||||
|
||||
\htmlonly
|
||||
<iframe src="../../js_histogram_backprojection_calcBackProject.html" width="100%"
|
||||
onload="this.style.height=this.contentDocument.body.scrollHeight +'px';">
|
||||
</iframe>
|
||||
\endhtmlonly
|
||||
@@ -0,0 +1,51 @@
|
||||
Histograms - 1 : Find, Plot, Analyze !!! {#tutorial_js_histogram_begins}
|
||||
========================================
|
||||
|
||||
Goal
|
||||
----
|
||||
|
||||
- Find histograms
|
||||
- Plot histograms
|
||||
- You will learn the function: **cv.calcHist()**.
|
||||
|
||||
Theory
|
||||
------
|
||||
|
||||
So what is histogram ? You can consider histogram as a graph or plot, which gives you an overall
|
||||
idea about the intensity distribution of an image. It is a plot with pixel values (ranging from 0 to
|
||||
255, not always) in X-axis and corresponding number of pixels in the image on Y-axis.
|
||||
|
||||
It is just another way of understanding the image. By looking at the histogram of an image, you get
|
||||
intuition about contrast, brightness, intensity distribution etc of that image. Almost all image
|
||||
processing tools today, provides features on histogram. Below is an image from [Cambridge in Color
|
||||
website](http://www.cambridgeincolour.com/tutorials/histograms1.htm), and I recommend you to visit
|
||||
the site for more details.
|
||||
|
||||

|
||||
|
||||
You can see the image and its histogram. (Remember, this histogram is drawn for grayscale image, not
|
||||
color image). Left region of histogram shows the amount of darker pixels in image and right region
|
||||
shows the amount of brighter pixels. From the histogram, you can see dark region is more than
|
||||
brighter region, and amount of midtones (pixel values in mid-range, say around 127) are very less.
|
||||
|
||||
Find Histogram
|
||||
--------------
|
||||
|
||||
We use the function: **cv.calcHist (image, channels, mask, hist, histSize, ranges, accumulate = false)**
|
||||
|
||||
@param image source arrays. They all should have the same depth, cv.CV_8U, cv.CV_16U or cv.CV_32F , and the same size. Each of them can have an arbitrary number of channels.
|
||||
@param channels list of the dims channels used to compute the histogram.
|
||||
@param mask optional mask. If the matrix is not empty, it must be an 8-bit array of the same size as images[i] . The non-zero mask elements mark the array elements counted in the histogram.
|
||||
@param hist output histogram(cv.CV_32F type), which is a dense or sparse dims -dimensional array.
|
||||
@param histSize array of histogram sizes in each dimension.
|
||||
@param ranges array of the dims arrays of the histogram bin boundaries in each dimension.
|
||||
@param accumulate accumulation flag. If it is set, the histogram is not cleared in the beginning when it is allocated. This feature enables you to compute a single histogram from several sets of arrays, or to update the histogram in time.
|
||||
|
||||
Try it
|
||||
------
|
||||
|
||||
\htmlonly
|
||||
<iframe src="../../js_histogram_begins_calcHist.html" width="100%"
|
||||
onload="this.style.height=this.contentDocument.body.scrollHeight +'px';">
|
||||
</iframe>
|
||||
\endhtmlonly
|
||||
@@ -0,0 +1,63 @@
|
||||
Histograms - 2: Histogram Equalization {#tutorial_js_histogram_equalization}
|
||||
======================================
|
||||
|
||||
Goal
|
||||
----
|
||||
|
||||
- We will learn the concepts of histogram equalization and use it to improve the contrast of our
|
||||
images.
|
||||
|
||||
Theory
|
||||
------
|
||||
|
||||
Consider an image whose pixel values are confined to some specific range of values only. For eg,
|
||||
brighter image will have all pixels confined to high values. But a good image will have pixels from
|
||||
all regions of the image. So you need to stretch this histogram to either ends (as given in below
|
||||
image, from wikipedia) and that is what Histogram Equalization does (in simple words). This normally
|
||||
improves the contrast of the image.
|
||||
|
||||

|
||||
|
||||
I would recommend you to read the wikipedia page on [Histogram
|
||||
Equalization](http://en.wikipedia.org/wiki/Histogram_equalization) for more details about it. It has
|
||||
a very good explanation with worked out examples, so that you would understand almost everything
|
||||
after reading that.
|
||||
|
||||
Histograms Equalization in OpenCV
|
||||
---------------------------------
|
||||
|
||||
We use the function: **cv.equalizeHist (src, dst)**
|
||||
|
||||
@param src source 8-bit single channel image.
|
||||
@param dst destination image of the same size and type as src.
|
||||
|
||||
Try it
|
||||
------
|
||||
|
||||
\htmlonly
|
||||
<iframe src="../../js_histogram_equalization_equalizeHist.html" width="100%"
|
||||
onload="this.style.height=this.contentDocument.body.scrollHeight +'px';">
|
||||
</iframe>
|
||||
\endhtmlonly
|
||||
|
||||
CLAHE (Contrast Limited Adaptive Histogram Equalization)
|
||||
--------------------------------------------------------
|
||||
|
||||
In **adaptive histogram equalization**, image is divided into small blocks called "tiles" (tileSize is 8x8 by default in OpenCV). Then each of these blocks are histogram equalized as usual. So in a small area, histogram would confine to a small region
|
||||
(unless there is noise). If noise is there, it will be amplified. To avoid this, **contrast limiting** is applied. If any histogram bin is above the specified contrast limit (by default 40 in OpenCV), those pixels are clipped and distributed uniformly to other bins before applying histogram equalization. After equalization, to remove artifacts in tile borders, bilinear interpolation is applied.
|
||||
|
||||
We use the class: **cv.CLAHE (clipLimit = 40, tileGridSize = new cv.Size(8, 8))**
|
||||
|
||||
@param clipLimit threshold for contrast limiting.
|
||||
@param tileGridSize size of grid for histogram equalization. Input image will be divided into equally sized rectangular tiles. tileGridSize defines the number of tiles in row and column.
|
||||
|
||||
@note Don't forget to delete CLAHE!
|
||||
|
||||
Try it
|
||||
------
|
||||
|
||||
\htmlonly
|
||||
<iframe src="../../js_histogram_equalization_createCLAHE.html" width="100%"
|
||||
onload="this.style.height=this.contentDocument.body.scrollHeight +'px';">
|
||||
</iframe>
|
||||
\endhtmlonly
|
||||
@@ -0,0 +1,14 @@
|
||||
Histograms in OpenCV.js {#tutorial_js_table_of_contents_histograms}
|
||||
====================
|
||||
|
||||
- @subpage tutorial_js_histogram_begins
|
||||
|
||||
Learn the basics of histograms
|
||||
|
||||
- @subpage tutorial_js_histogram_equalization
|
||||
|
||||
Learn to Equalize Histograms to get better contrast for images
|
||||
|
||||
- @subpage tutorial_js_histogram_backprojection
|
||||
|
||||
Learn histogram backprojection to segment colored objects
|
||||
Reference in New Issue
Block a user