예제 #1
0
import cv2
import matplotlib.pyplot as plt
import numpy as np
import sys

sys.path.append("..")
from Question_01_10.q2 import Gray
import math

img = cv2.imread('image_41_50/imori.jpg')
img = Gray(img).astype(np.uint8)

img_padded = cv2.copyMakeBorder(img, 1, 1, 1, 1, cv2.BORDER_CONSTANT, value=0)
img_gaussianed = cv2.GaussianBlur(img_padded, (5, 5), sigmaX=1.4)
img_gaussianed = np.clip(img_gaussianed, 0, 255).astype(np.uint8)

print(img_gaussianed)

sobel_x = cv2.Sobel(img_gaussianed.copy(), cv2.CV_32F, dx=1, dy=0, ksize=3)
sobel_y = cv2.Sobel(img_gaussianed.copy(), cv2.CV_32F, dx=0, dy=1, ksize=3)
sobel_x = np.clip(sobel_x, 0, 255).astype(np.uint8)
sobel_y = np.clip(sobel_y, 0, 255).astype(np.uint8)
#重み付き和

edge = np.sqrt(np.power(sobel_x, 2) + np.power(sobel_y, 2))
#edge = np.array(edge, dtype=np.float32)
sobel_x = np.maximum(sobel_x, 1e-5)
angle = np.arctan(sobel_y / sobel_x)
angle = angle * (180 / np.pi)
angle = np.where((angle <= 22.5) & (angle > -22.5), 0, angle)
angle = np.where((22.5 < angle) & (angle <= 67.5), 45, angle)
예제 #2
0
    img_zero = zero_padding(img).astype(np.float)
    out = img_zero.copy()

    K = [[-2., -1., 0.],[-1., 1., 1.],[0., 1., 2.]]

    for y in range(H):
        for x in range(W):
            out[pad+y, pad+x] = np.sum(K*img_zero[y:y+K_size, x:x+K_size])

    print(out)
    print("ーーーーーーーーーーーーーー")

    out = np.clip(out, 0, 255)

    print(out)
    print("ーーーーーーーーーーーーーー")

    out = out[pad:pad+H, pad:pad+W].astype(np.uint8)
    return out



img = cv2.imread("./image_11_20/imori.jpg").astype(np.float)
img_gray = Gray(img)
img_ans = emboss_fillter(img_gray)

cv2.imwrite("./image_11_20/answer18.jpg", img_ans)
cv2.imshow("result", img_ans)
cv2.waitKey(0)
cv2.destroyAllWindows()
예제 #3
0
import cv2
import numpy as np
import matplotlib.pyplot as plt

import sys
sys.path.append("..")
from Question_01_10.q2 import Gray

img = cv2.imread("./image_11_20/imori_dark.jpg")

plt.hist(img.ravel(), bins=255, rwidth=0.8, range=(0, 255))
plt.savefig("out.png")
plt.show()

img_g = Gray(img)
plt.hist(img_g.ravel(), bins=255, rwidth=0.8, range=(0, 255))
plt.savefig("out_g.png")
plt.show()