Created
June 21, 2019 12:35
-
-
Save chizuchizu/950b02f180d7f61bb7e6a43162f6a266 to your computer and use it in GitHub Desktop.
フーリエ変換
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
import pandas as pd | |
from tqdm import tqdm | |
from numba import jit | |
from sklearn.preprocessing import MinMaxScaler | |
img = cv2.imread("/home/yuma/PycharmProjects/deeplearning/Gasyori100knock-master/Question_31_40/imori.jpg") | |
print(img.shape) | |
shape = img.shape | |
img2 = img[:, :, 2] * 0.2126 + img[:, :, 1] * 0.7152 + img[:, :, 0] * 0.0722 | |
print(img2.shape) | |
out = np.zeros_like(img2).astype(np.complex) | |
out2 = np.zeros_like(out) | |
@jit | |
def G(k, l, img): | |
res = 0 | |
for x in range(128): | |
for y in range(128): | |
memo = np.exp(-2j * np.pi * (k * x / 128 + l * y / 128) / 128) * img[x, y] | |
res += memo | |
return res | |
@jit | |
def F(out, img2): | |
for i in range(128): | |
for j in range(128): | |
out[i, j] = G(i, j, img2) | |
return out | |
@jit | |
def Gr(k, l, img): | |
res = 0 | |
for x in range(128): | |
for y in range(128): | |
memo = np.exp(2j * np.pi * (k * x / 128 + l * y / 128) / np.sqrt(128 * 128)) | |
res += memo * img[x, y] | |
return res | |
@jit | |
def Fr(out, out2): | |
for i in range(128): | |
for j in range(128): | |
out2[i, j] = np.abs(Gr(i, j, out)) | |
return out2 | |
Gt = F(out, img2) | |
ps = (np.abs(Gt) / np.abs(Gt).max() * 255).astype(np.uint8) | |
print(np.max(np.abs(Gt))) | |
cv2.imwrite("out_ps.jpg", ps) | |
out = Fr(Gt, out) | |
print(out) | |
# mmsc = MinMaxScaler(feature_range=(0, 255)) | |
# out = mmsc.fit_transform(out) | |
# out = normalize(out, 0, 255) | |
print(np.max(out)) | |
print(np.min(out)) | |
out[out < 0] = 0 | |
out[out > 255] = 255 | |
out = out.astype(np.uint8) | |
# # 出力 | |
cv2.imshow("result", out) | |
cv2.waitKey(0) | |
cv2.imwrite("out.jpg", out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment