Skip to content
Snippets Groups Projects
Commit 52eb3bc0 authored by Amanuel Aslan's avatar Amanuel Aslan
Browse files

Update DIP2-cheatsheet.md

parent 226e7be9
No related tags found
No related merge requests found
......@@ -36,6 +36,7 @@ np.linspace(0,2,num=9, dtype) # evenly spaced values. Specify the number of valu
np.eye(2, dtype) # 2x2 identity matrix
np.random.random((2,2)) # 2x2 array with random [0..1) values
np.random.randint(low, high, (2, 2)) # 2x2 array with random integers from [low, high[ (w/o high!)
img_th = (img > threshold) * pixel # (img > threshold) returns array with ones where true
```
### Array operations
......@@ -51,6 +52,8 @@ np.maximum(array1, array2) # Returns new array with shape of array1 and array2 w
Calculate smallest *odd* interger not smaller than value (usefull for kernel size for gaussian filter)
```python
int(np.ceil(value) // 2 * 2 + 1)
# Alternative
n = value if value % 2 == 1 else value + 1
```
Change type of the values of a numpy array. Possible types: *np.float32*,*np.float64*,*np.int32*, *np.[u]int16*, *np.[u]int32*, *np.[u]int64*
```python
......@@ -76,6 +79,12 @@ rows, cols (,channels) = img.shape #channels only if color image
n_pixels = img.size # = rows*cols*channels
img.dtype
```
- Multiplication types
```python
np.dot(x1, x2) # dot product of x1 and x2
np.multiply(x1, x2) # element wise multiplicatoin of x1 and x2
np.matmul(x1, x2) # matrix multiplication of x1 and x2
```
## Image manipulation
......@@ -99,6 +108,8 @@ cv2.filter2D(img, ddepth=-1, w_gauss/np.sum(w_gauss))
cv2.filter2D(img, ddepth=cv2.CV_16S, w_sobel)
# Normalize image between given minimum and maximum
cv2.normalize(img, NONE, min_val, max_val, cv2.NORM_MINMAX)
# directly apply gaussian blur to image
cv2.GaussianBlur(img.astype(np.float64), (n, n), sigma)
```
### Frequency domain
......@@ -155,6 +166,10 @@ plt.axvline(value, color="red") # vertical line at x="value"
plt.axhline(100, color="blue") # horizontal line at y=100
```
### Dots
```python
plt.plot(pos[i], pos[j], 'ro', label='label1') # plot dots in red for position pos[i], pos[j]
```
# Misc
## Depth combinations
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment