Skip to content

Commit 5f7530e

Browse files
Create README.md
1 parent a05a85d commit 5f7530e

File tree

1 file changed

+151
-0
lines changed

1 file changed

+151
-0
lines changed

README.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# Image-processing
2+
3+
This repo contains all my learnings in Open-CV
4+
5+
## Basics
6+
### Image-openning
7+
The source code is <a href="https://github.com/Blackcipher101/Image-processing/blob/master/Image-open.py">here</a>
8+
9+
Opencv has function ```cv2.imread(str,channel)``` it takes the arguments of string(filename or path) and the channel 0 corresponds to B/W and 1 corresponds to Color.
10+
It can open BMP, JPEG, PNG, PPM, RAS file formats and convert them to ```cv2.Mat``` which is basically a matrix like
11+
#### B/W
12+
[ [2 3 4 5 6 7 8]<br>
13+
[2 3 4 5 1 8 4]<br>
14+
[6 7 8 9 3 4 5] ]<br>
15+
#### Color
16+
[ [[100 34 25] [100 34 25] [100 34 25] [100 34 25]
17+
[100 34 25] [100 34 25] [100 34 25][100 34 25]
18+
[100 34 25] [100 34 25] [100 34 25] [100 34 25]]
19+
20+
```cv2.imshow((str),matrix)``` which can open the martrix to image the string is the name of the window
21+
if the image is to large one can use ```cv2.namedWindow('image', cv.WINDOW_NORMAL)``` it allows you to resize the window
22+
23+
<img src="images/open.png">
24+
25+
### Opening Video
26+
27+
```cv2.VideoCapture(str)``` takes path to a video file or 0 for webcam it returns a stream image which can then be read into matrix and displayed using ```cv2.imshow((str),matrix)```
28+
```cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)``` this converts the channel to B/W (don't get scared newbies what is channel its basically way you define color like RGB)
29+
<img src="images/video.png">
30+
31+
### Creating a video-player with seekbar
32+
33+
Opencv has a function to create a trackbar you can call a function on change
34+
```python
35+
def onChange(trackbarValue):
36+
global cap
37+
cap.set(1,trackbarValue)
38+
```
39+
```cv2.createTrackbar( 'trackbar', 'frame', 0, length, onChange)```
40+
and then you set the cap to a certain value
41+
42+
For pausing I basically stopped the cap reading new images
43+
So s pause and r runs
44+
<img src="images/video-player.png">
45+
46+
### Drawing
47+
In opencv we can use functions ```cv2.line()``` ```cv2.rectangle()``` ```cv2.circle()``` ```cv2.ellipise()``` ```cv2.polylines()```
48+
for more info on the functions go to <a src="https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_drawing_functions/py_drawing_functions.html#drawing-functions">docs</a>
49+
50+
## Image processing
51+
52+
### Object-tracking(based on color)
53+
So we convert the image to HSV ```cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)``` we changed to HSV because it gives us a range of colors with change of value.
54+
We make a image thresholding ```cv2.inRange(hsv, lower_blue, upper_blue)``` with a range and then we <strong>and with every pixel of both</strong> ```cv2.bitwise_and()``` it with the image so results in image only with the object
55+
56+
<img src="images/object_track.png">
57+
58+
### Thresholding
59+
In Opencv we set a pixel value with respect to another pixel value like<br>
60+
if its less than a certain value it will be set to certain if not then to another
61+
``` if x>125: then x=225 else x=0 ```
62+
63+
There are various ones like THRESH_BINARY,THRESH_BINARY_INV,THRESH_TRUNC,THRESH_TOZERO,THRESH_TOZERO_INV
64+
65+
<img src="images/thresh.png">
66+
67+
#### Adaptive thresholding
68+
This is a method where we decide the max value based on region of image
69+
```cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\cv2.THRESH_BINARY,11,2)```
70+
71+
But when we have bimodal images(images with two peaks in a histogram)
72+
We <strong>Otsu,Riddler-Cavldier and Killer IIingworth</strong>method.
73+
<img src="images/otsu.png">
74+
75+
### Image smoothing
76+
77+
Image smoothing is just removal of the edges which results in a blurred image it is done by calling ```cv2.GassuianBlur()```. It allows to reduce the noise in the image
78+
but we loose some infomartation in the process Gaussain Blur by taking an average of 5X5 matrix.
79+
80+
<img src="gauss.png">
81+
82+
### Morphigical Transformatations
83+
Its a opertation on we do on binary to erode or diilate images
84+
<img src="morph.png">
85+
### Image gradients
86+
We use```cv2.sobel()``` to find image deratives across a direction it gives us the edges in one direction
87+
<img src="images/sobel.png">
88+
We also get edges in both direction in x-y directation
89+
<img src="images/lap.png">
90+
### Edge detection
91+
We use the function ```cv2.Canny()``` The algorithm is Noise Reduction -> Finding Intensity Gradient of the Image -> Non-maximum Suppression -> Hysteresis Thresholding
92+
The basic method is to apply image in gradient in 4 or more direction and the apply suppersion and then find the sure edges.
93+
<img src="images/edge.png">
94+
### Image Blending
95+
This we make images arrays by downscaling the image and also the laplacian
96+
then we keep adding the half of both the laplacian and then masking the image with the orginal
97+
<img src="images/blend.png">
98+
99+
### Image contorors
100+
Contours can be explained simply as a curve joining all the continuous points (along the boundary), having same color or intensity. The contours are a useful tool for shape analysis and object detection and recognition.
101+
We can use these contours to find moments,area,perimeter and many other informatation.
102+
103+
We can apporximate contours to make the processing of informamtaton faster without the loss of important informatation.
104+
<img src="images/contours.png">
105+
106+
###Draw Histogram
107+
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.
108+
<img src="image/histogram.png">
109+
110+
#### Enhanced image
111+
The image have a better as it improves the image by adding pixels whose frecquency is less.
112+
<img src="images/enhanced.png">
113+
114+
#### CLAHE
115+
It would be better if we could localize the equliztation so CLAHE(Contrast Limited Adaptive Histogram Equalization) was put fowrard
116+
<img src="images/Clahe.png">
117+
#### Backprogagtation
118+
We use this to find the object of interst .As we know the certain frequency of pixels we can find it
119+
<img src="images/BKpropagate.png">
120+
121+
122+
### Template matching
123+
We can find certainpart of a image by matching the image to a current template
124+
They have various methods but most of the times cv2.TM_CCOEFF works best
125+
<img src="images/template.png">
126+
127+
### Image segmentation With watershed Algorithm
128+
We have to segment the images into its smallest constuient parts
129+
Algorithm
130+
Threshold->Morphlogical opertations->Transforms->Mask\
131+
<img src="images/imgsege.png">
132+
### Foregourd Subtractation
133+
We use the Grabcut algorithm to remove the backgroung image and also apply mask to improve the accuracy
134+
<img src="images/foresub.png">
135+
136+
## Fearture detection
137+
We will be looking at many algorithms that detect corners
138+
139+
### Harris corner detection
140+
It basically finds the difference in intensity for a displacement of (u,v) in all directions.
141+
<img src="images/harris.png">
142+
143+
### FAST
144+
Select a pixel p in the image which is to be identified as an interest point or not. Let its intensity be I_p. -> Select appropriate threshold value t. -> Now the pixel p is a corner if there exists a set of n contiguous pixels in the circle (of 16 pixels) which are all brighter than I_p + t, or all darker than I_p − t. n was chosen to be 12. -> A high-speed test was proposed to exclude a large number of non-corners.
145+
<img src="images/fast.png">
146+
147+
### ORB
148+
We have a perfect mixture and also the point its not patented
149+
150+
<img src="images/ORB.png">
151+

0 commit comments

Comments
 (0)