Note
Note
html
// Tutoriald
https://opencv24-python-tutorials.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_filtering/
py_filtering.html
//
https://homepages.inf.ed.ac.uk/rbf/HIPR2/wksheets.htm
https://www.tutorialspoint.com/dip/gray_level_transformations.htm
https://medium.com/jun94-devpblog/cv-2-gaussian-and-median-filter-separable-2d-filter-
2d11ee022c66
https://stackoverflow.com/questions/20638912/should-i-choose-mean-or-median-filter-for-gaussian-
noise
Median vs gaus : sometime gaus cannot remove salt and pepper -> median filter apper to help
Blur = filter
As a general rule of thumb - if your noise is salt-n-pepper you should use the
median filter. If you assume that the original signal is low frequency (like a
smooth surface with no texture) then the gaussian filter is a good choice. Box
filter (mean) is usually used to approximate the gaussian filter. For removing
white noise you could use the Wiener filter.
24 bit - RGB
1.Image negative
S= outpu
r = input pixel
2. 1Log transformation
Replace all pixel with log value
3 Gamma transform
Gamma correction or gamma is a nonlinear operation used to encode and decode luminance or
tristimulus values in video or still image systems.
5. Histograms
A histogram is a graph. A graph that shows frequency of anything. Usually histogram have bars
that represent frequency of occurring of data in the whole data set.
Histogram of an image
Histogram of an image, like other histograms also shows frequency. But an image
histogram, shows frequency of pixels intensity values. In an image histogram, the x axis
shows the gray level intensities and the y axis shows the frequency of these intensities.
Threshold and histogram or other technique – sol ex1
Histogram Stretching
The formula for stretching the histogram of the image to increase the contrast is
The formula requires finding the minimum and maximum pixel intensity multiply by
levels of gray. In our case the image is 8bpp, so levels of gray are 256.
The minimum value is 0 and the maximum value is 225. So the formula in our case is
where f(x,y) denotes the value of each pixel intensity. For each f(x,y) in an image , we
will calculate this formula.
After doing this, we will be able to enhance our contrast.
Contrast 225 -> 240
Filters are applied on image for multiple purposes. The two most common uses are as
following:
Blurring
In blurring, we simple blur an image. An image looks more sharp or more detailed if we
are able to perceive all the objects and their shapes correctly in it. For example. An
image with a face, looks clear when we are able to identify eyes, ears, nose, lips,
forehead e.t.c very clear. This shape of an object is due to its edges. So in blurring, we
simple reduce the edge content and makes the transition form one color to the other
very smooth.
Types of filters
Blurring can be achieved by many ways. The common type of filters that are used to
perform blurring are.
Mean filter
Weighted average filter
Gaussian filter
Types of edges
Generally edges are of three types:
Horizontal edges
Vertical Edges
Diagonal Edges
Sharpening
Sharpening is opposite to the blurring. In blurring, we reduce the edge content and in
Sharpening, we increase the edge content. So in order to increase the edge content in
an image, we have to find edges first.
Prewitt operator is used for edge detection in an image. It detects two types of edges
Horizontal edges
Vertical Edges
Edges are calculated by using difference between corresponding pixel intensities of an image
Sobel Operator
Laplacian Operator is also a derivative operator which is used to find edges in an image. The
major difference between Laplacian and other operators like Prewitt, Sobel, Robinson and
Kirsch is that these all are first order derivative masks but Laplacian is a second order
derivative mask. In this mask we have two further classifications one is Positive Laplacian
Operator and other is Negative Laplacian Operator.
4. Contrast stretching
Contrast stretching (often called normalization) is a simple image enhancement technique that
attempts to improve the contrast in an image by 'stretching' the range of intensity values it
contains to span a desired range of values, the full range of pixel values that the image type
concerned allows.
BT Ex
1. Threshold – equal histogram (dieu chinh contrast ) – median filter (phep loc ) –
Dilataion or erosion ( open or closing ) -> detect edge ( canny , … )
Smoothing Filters
21
numpy uses tuples as indexes. In this case, this is a detailed slice assignment.
[0] #means line 0 of your matrix
[(0,0)] #means cell at 0,0 of your matrix
[0:1] #means lines 0 to 1 excluded of your matrix
[:1] #excluding the first value means all lines until line 1 excluded
[1:] #excluding the last param mean all lines starting form line 1
included
[:] #excluding both means all lines
[::2] #the addition of a second ':' is the sampling. (1 item every 2)
[::] #exluding it means a sampling of 1
[:,:] #simply uses a tuple (a single , represents an empty tuple) instead
of an index.