Skip to content

Commit

Permalink
文件夹修复
Browse files Browse the repository at this point in the history
  • Loading branch information
gzr2017 committed Nov 26, 2019
1 parent e73ea60 commit 597205b
Show file tree
Hide file tree
Showing 78 changed files with 2,454 additions and 3,837 deletions.
Binary file added Question_01_10/imori.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Question_01_10/imori_noise.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Question_31_40/assets/dct_equ.png
Binary file not shown.
Binary file removed Question_31_40/assets/dft_equ.png
Binary file not shown.
Binary file removed Question_31_40/assets/idct_equ.png
Binary file not shown.
Binary file removed Question_31_40/assets/idct_equ2.png
Binary file not shown.
Binary file removed Question_31_40/assets/idft_equ.png
Binary file not shown.
Binary file removed Question_31_40/assets/psnr_mse_equ.png
Binary file not shown.
Binary file added Question_41_50/.DS_Store
Binary file not shown.
8 changes: 5 additions & 3 deletions Question_41_50/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
问题41至问题43是边缘检测方法中的一种——Canny 边缘检测法的理论介绍。

1. 使用高斯滤波;
2. 在x方向和y方向上使用 Sobel 滤波器,在此之上求出边缘的强度和边缘的梯度;
2. 在$x$方向和$y$方向上使用Sobel滤波器,在此之上求出边缘的强度和边缘的梯度;
3. 对梯度幅值进行非极大值抑制(Non-maximum suppression)来使边缘变得更细;
4. 使用滞后阈值来对阈值进行处理。

Expand Down Expand Up @@ -212,9 +212,11 @@ x = - sin(t) / cos(t) * y + r / cos(t)
## Q.50. 闭运算(Closing Operation)
Canny 边缘检测之后,进行闭处理吧(N=1)。
Canny边缘检测之后,进行$N=1$的闭处理吧。
闭运算,即先进行$N$次膨胀再进行$N$次腐蚀。
闭运算,即先进行N次膨胀再进行N次腐蚀。
闭运算能够将中断的像素连接起来。
Expand Down
76 changes: 46 additions & 30 deletions Question_61_70/answers/answer_61.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,54 @@
import numpy as np
import matplotlib.pyplot as plt

# Connect 4
def connect_4(img):
# get shape
H, W, C = img.shape

# prepare temporary image
tmp = np.zeros((H, W), dtype=np.int)

# binarize
tmp[img[..., 0] > 0] = 1

# prepare out image
out = np.zeros((H, W, 3), dtype=np.uint8)

# each pixel
for y in range(H):
for x in range(W):
if tmp[y, x] < 1:
continue

S = 0
S += (tmp[y,min(x+1,W-1)] - tmp[y,min(x+1,W-1)] * tmp[max(y-1,0),min(x+1,W-1)] * tmp[max(y-1,0),x])
S += (tmp[max(y-1,0),x] - tmp[max(y-1,0),x] * tmp[max(y-1,0),max(x-1,0)] * tmp[y,max(x-1,0)])
S += (tmp[y,max(x-1,0)] - tmp[y,max(x-1,0)] * tmp[min(y+1,H-1),max(x-1,0)] * tmp[min(y+1,H-1),x])
S += (tmp[min(y+1,H-1),x] - tmp[min(y+1,H-1),x] * tmp[min(y+1,H-1),min(x+1,W-1)] * tmp[y,min(x+1,W-1)])

if S == 0:
out[y,x] = [0, 0, 255]
elif S == 1:
out[y,x] = [0, 255, 0]
elif S == 2:
out[y,x] = [255, 0, 0]
elif S == 3:
out[y,x] = [255, 255, 0]
elif S == 4:
out[y,x] = [255, 0, 255]

out = out.astype(np.uint8)

return out



# Read image
img = cv2.imread("renketsu.png").astype(np.float32)
H, W, C = img.shape

tmp = np.zeros((H, W), dtype=np.int)
tmp[img[..., 0]>0] = 1

out = np.zeros((H, W, 3), dtype=np.uint8)

for y in range(H):
for x in range(W):
if tmp[y, x] < 1:
continue

c = 0
c += (tmp[y,min(x+1,W-1)] - tmp[y,min(x+1,W-1)] * tmp[max(y-1,0),min(x+1,W-1)] * tmp[max(y-1,0),x])
c += (tmp[max(y-1,0),x] - tmp[max(y-1,0),x] * tmp[max(y-1,0),max(x-1,0)] * tmp[y,max(x-1,0)])
c += (tmp[y,max(x-1,0)] - tmp[y,max(x-1,0)] * tmp[min(y+1,H-1),max(x-1,0)] * tmp[min(y+1,H-1),x])
c += (tmp[min(y+1,H-1),x] - tmp[min(y+1,H-1),x] * tmp[min(y+1,H-1),min(x+1,W-1)] * tmp[y,min(x+1,W-1)])

if c == 0:
out[y,x] = [0, 0, 255]
elif c == 1:
out[y,x] = [0, 255, 0]
elif c == 2:
out[y,x] = [255, 0, 0]
elif c == 3:
out[y,x] = [255, 255, 0]
elif c == 4:
out[y,x] = [255, 0, 255]

out = out.astype(np.uint8)

# connect 4
out = connect_4(img)

# Save result
cv2.imwrite("out.png", out)
Expand Down
81 changes: 49 additions & 32 deletions Question_61_70/answers/answer_62.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,57 @@
import numpy as np
import matplotlib.pyplot as plt

# connect 8
def connect_8(img):
# get shape
H, W, C = img.shape

# prepare temporary
_tmp = np.zeros((H, W), dtype=np.int)

# get binarize
_tmp[img[..., 0] > 0] = 1

# inverse for connect 8
tmp = 1 - _tmp

# prepare image
out = np.zeros((H, W, 3), dtype=np.uint8)

# each pixel
for y in range(H):
for x in range(W):
if _tmp[y, x] < 1:
continue

S = 0
S += (tmp[y,min(x+1,W-1)] - tmp[y,min(x+1,W-1)] * tmp[max(y-1,0),min(x+1,W-1)] * tmp[max(y-1,0),x])
S += (tmp[max(y-1,0),x] - tmp[max(y-1,0),x] * tmp[max(y-1,0),max(x-1,0)] * tmp[y,max(x-1,0)])
S += (tmp[y,max(x-1,0)] - tmp[y,max(x-1,0)] * tmp[min(y+1,H-1),max(x-1,0)] * tmp[min(y+1,H-1),x])
S += (tmp[min(y+1,H-1),x] - tmp[min(y+1,H-1),x] * tmp[min(y+1,H-1),min(x+1,W-1)] * tmp[y,min(x+1,W-1)])

if S == 0:
out[y,x] = [0, 0, 255]
elif S == 1:
out[y,x] = [0, 255, 0]
elif S == 2:
out[y,x] = [255, 0, 0]
elif S == 3:
out[y,x] = [255, 255, 0]
elif S == 4:
out[y,x] = [255, 0, 255]

out = out.astype(np.uint8)

return out


# Read image
img = cv2.imread("renketsu.png").astype(np.float32)
H, W, C = img.shape

_tmp = np.zeros((H, W), dtype=np.int)
_tmp[img[..., 0]>0] = 1

tmp = 1 - _tmp

out = np.zeros((H, W, 3), dtype=np.uint8)

for y in range(H):
for x in range(W):
if _tmp[y, x] < 1:
continue

c = 0
c += (tmp[y,min(x+1,W-1)] - tmp[y,min(x+1,W-1)] * tmp[max(y-1,0),min(x+1,W-1)] * tmp[max(y-1,0),x])
c += (tmp[max(y-1,0),x] - tmp[max(y-1,0),x] * tmp[max(y-1,0),max(x-1,0)] * tmp[y,max(x-1,0)])
c += (tmp[y,max(x-1,0)] - tmp[y,max(x-1,0)] * tmp[min(y+1,H-1),max(x-1,0)] * tmp[min(y+1,H-1),x])
c += (tmp[min(y+1,H-1),x] - tmp[min(y+1,H-1),x] * tmp[min(y+1,H-1),min(x+1,W-1)] * tmp[y,min(x+1,W-1)])

if c == 0:
out[y,x] = [0, 0, 255]
elif c == 1:
out[y,x] = [0, 255, 0]
elif c == 2:
out[y,x] = [255, 0, 0]
elif c == 3:
out[y,x] = [255, 255, 0]
elif c == 4:
out[y,x] = [255, 0, 255]

out = out.astype(np.uint8)

# connect 8
out = connect_8(img)


# Save result
cv2.imwrite("out.png", out)
Expand Down
Binary file modified Question_61_70/answers/answer_63.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 54 additions & 38 deletions Question_61_70/answers/answer_63.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,62 @@
import numpy as np
import matplotlib.pyplot as plt

# Read image
img = cv2.imread("gazo.png").astype(np.float32)
H, W, C = img.shape

out = np.zeros((H, W), dtype=np.int)
out[img[..., 0]>0] = 1

count = 1
while count > 0:
count = 0
tmp = out.copy()
for y in range(H):
for x in range(W):
if out[y, x] < 1:
continue

judge = 0

## condition 1
if (tmp[y,min(x+1,W-1)] + tmp[max(y-1,0), x] + tmp[y,max(x-1,0)] + tmp[min(y+1,H-1),x]) < 4:
judge += 1

# thining algorythm
def thining(img):
# get shape
H, W, C = img.shape

# prepare out image
out = np.zeros((H, W), dtype=np.int)
out[img[..., 0] > 0] = 1

count = 1
while count > 0:
count = 0
tmp = out.copy()
# each pixel ( rasta scan )
for y in range(H):
for x in range(W):
# skip black pixel
if out[y, x] < 1:
continue

# count satisfied conditions
judge = 0

## condition 2
c = 0
c += (out[y,min(x+1,W-1)] - out[y,min(x+1,W-1)]*out[max(y-1,0),min(x+1,W-1)]*out[max(y-1,0),x])
c += (out[max(y-1,0),x] - out[max(y-1,0),x]*out[max(y-1,0),max(x-1,0)]*out[y,max(x-1,0)])
c += (out[y,max(x-1,0)] - out[y,max(x-1,0)]*out[min(y+1,H-1),max(x-1,0)]*out[min(y+1,H-1),x])
c += (out[min(y+1,H-1),x] - out[min(y+1,H-1),x]*out[min(y+1,H-1),min(x+1,W-1)]*out[y,min(x+1,W-1)])
if c == 1:
judge += 1
## condition 1
if (tmp[y, min(x+1, W-1)] + tmp[max(y-1, 0), x] + tmp[y, max(x-1, 0)] + tmp[min(y+1, H-1), x]) < 4:
judge += 1

## condition 2
c = 0
c += (tmp[y,min(x+1, W-1)] - tmp[y, min(x+1, W-1)] * tmp[max(y-1, 0),min(x+1, W-1)] * tmp[max(y-1, 0), x])
c += (tmp[max(y-1,0), x] - tmp[max(y-1,0), x] * tmp[max(y-1, 0), max(x-1, 0)] * tmp[y, max(x-1, 0)])
c += (tmp[y, max(x-1, 0)] - tmp[y,max(x-1, 0)] * tmp[min(y+1, H-1), max(x-1, 0)] * tmp[min(y+1, H-1), x])
c += (tmp[min(y+1, H-1), x] - tmp[min(y+1, H-1), x] * tmp[min(y+1, H-1), min(x+1, W-1)] * tmp[y, min(x+1, W-1)])
if c == 1:
judge += 1

##x condition 3
if np.sum(tmp[max(y-1, 0) : min(y+2, H), max(x-1, 0) : min(x+2, W)]) >= 4:
judge += 1

##x condition 3
if np.sum(out[max(y-1,0):min(y+2,H), max(x-1,0):min(x+2,W)]) >= 4:
judge += 1

if judge == 3:
out[y,x] = 0
count += 1

out = out.astype(np.uint8) * 255
# if all conditions are satisfied
if judge == 3:
out[y, x] = 0
count += 1

out = out.astype(np.uint8) * 255

return out


# Read image
img = cv2.imread("gazo.png").astype(np.float32)

# thining
out = thining(img)

# Save result
cv2.imwrite("out.png", out)
Expand Down
Binary file added Question_61_70/answers/answer_64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 597205b

Please sign in to comment.