LoginSignup
0
0

More than 5 years have passed since last update.

画像のフーリエ変換の仕方:欧州旗のパワースペクトルはイギリス国旗と多少似ている

Posted at

出力結果

左から順に欧州旗、欧州旗のパワースペクトル、イギリス国旗。
merged.png
欧州旗のパワースペクトル(フーリエ変換をおこない各成分の絶対値をとったもの)はイギリス国旗となんとなく似ている。

ソースコード

import numpy as np
import cv2
import urllib.request as req

# get and read EU's flag
url='http://freesozai.jp/itemStartDownload.php?category=nation_flag&page=ntf_004&type=sozai&file=1.png'
req.urlretrieve(url, "flag_EU.png")
img = cv2.imread("./flag_EU.png")

# convert gray scale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

#perform 2d fftw
fimg = np.fft.fft2(gray)
# Shift the zero-frequency component to the center of the spectrum.
fimg =  np.fft.fftshift(fimg)
# get power spectrum (without normalization)
abs_fimg = np.log(np.abs(fimg))

# get unionjack
url='http://freesozai.jp/itemStartDownload.php?category=nation_flag&page=ntf_305&type=sozai&file=1.png'
req.urlretrieve(url, "flag_UK.png")
img_UK = cv2.imread("./flag_UK.png")
gray_UK = cv2.cvtColor(img_UK, cv2.COLOR_BGR2GRAY)

# output figures
cv2.imwrite("flag_EU_gray.png",(gray))
cv2.imwrite("flag_EU_FF.png",(abs_fimg/np.max(abs_fimg)*255))
cv2.imwrite("flag_UK_gray.png",(gray_UK))

# merge the output figures with imagemagick
import os
os.system("convert +append flag_EU_gray.png flag_EU_FF.png flag_UK_gray.png merged.png" )
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0