https://docs.opencv.org/4.x/d7/d4d/tutorial_py_thresholding.
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.
8 bit color format : grey scale
Binary image 0,1
24 bit - RGB
1.Image negative
L = gray/intesity level = 2^8 = 256
S= outpu
r = input pixel
Formula S= L-1-r = 256 – 1 -r
A negative of an image is an image where its lightest areas appear as darkest and the darkest
areas appear as lightest
Image enhancement ( spatial domain )
2. 1Log transformation
Replace all pixel with log value
During log transformation, the dark pixels in an image
are expanded as compared to the higher pixel values.
The higher pixel values are kind of compressed in log
transformation. Meaning, darker pixel get brighter whereas the
brighter pixels don’t change much.
https://medium.com/alphavision/image-enhancement-46f4b7fda5b4
2.2 Inverse log transform
Brightness intensity = f(x,y)
Contrast = max intensity – min intensity
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.
Stretching -> threshold
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.
The x axis contains event whose frequency you have to count.
The y axis contains frequency.
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 sliding -> add more pixel to brighter
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
Failing of histogram stretching
As we have discussed , that the algorithm fails on some cases. Those cases include
images with when there is pixel intensity 0 and 255 are present in the image
Histogram Equalization
Histogram equalization is used to enhance contrast. It is not necessary that contrast will
always be increase in this. There may be some cases were histogram equalization can
be worse. In that cases the contrast is decreased.
during histogram equalization the overall shape of the histogram changes, where as in
histogram stretching the overall shape of histogram remains same.
Where have we reached until now
Till now we have discussed two important methods to manipulate images. Or in other
words we can say that, our black box works in two different ways till now.
The two different ways of manipulating images were
Graphs (Histograms)
This method is known as histogram processing. We have discussed it in detail in
previous tutorials for increase contrast, image enhancement, brightness e.t.c
Transformation functions
This method is known as transformations, in which we discussed different type of
transformations and some gray level transformations
Convolution
Convolution can achieve something, that the previous two methods of manipulating images
can’t achieve. Those include the blurring, sharpening, edge detection, noise reduction e.t.c.
Filters are applied on image for multiple purposes. The two most common uses are as
following:
Filters are used for Blurring and noise reduction
Filters are used or edge detection and sharpness
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.
Matrix add a+b
Matrix multiply 1 x 2 = ( 0 ,1 ) = hang 0 x cot 1 +
Piece wise Linear tranformation : gray level transformation
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 , … )
Filter or blur de lam ro diem anh hon
Smoothing Filters
Được sử dụng để giảm chuyển đổi sắc nét về cường độ
o Giảm chi tiết không liên quan trong ảnh (ví dụ: nhiễu)
o Làm mịn các đường viền sai do sử dụng không đủ số mức
cường độ trong ảnh
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.