Created
January 26, 2017 02:51
-
-
Save Gotoryoo/ba379f39df25bc95bbf64f009b31221b to your computer and use it in GitHub Desktop.
画像を回転させて、peakを取得するプログラム。
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
""" | |
Created on Tue Oct 11 15:08:07 2016 | |
@author: ryousuke | |
""" | |
#import os | |
import cv2 | |
import sys | |
import pandas as pd | |
#from os.path import join, relpath | |
#from glob import glob | |
from PIL import Image | |
#import math | |
import numpy as np | |
import ROOT | |
ROOT.std.__file__ = 'dummy_for_old_pyastro' | |
ROOT.gROOT.Reset() | |
c1 = ROOT.TCanvas( 'c1', 'Canvas', 700, 700 ) | |
track = np.ones((440,512),np.uint8) | |
track = np.zeros((440,512),np.uint8) | |
#img = np.zeros((330,30), np.uint8) | |
cv2.rectangle(track,(200,217),(300,223),(1,1,1),-1) | |
cv2.imshow('bigimg', track * 255) | |
cv2.waitKey(0) | |
cv2.destroyAllWindows() | |
center_x = 256 | |
center_y = 220 | |
scale = 1.0 | |
aaa = 'anglechange_ver2' | |
#angle = 80 | |
for angle in range(0,181): | |
center = tuple(np.array([center_x, center_y])) | |
size = tuple(np.array([track.shape[1], track.shape[0]])) | |
rotation_matrix = cv2.getRotationMatrix2D(center, angle, scale) | |
img_rot = cv2.warpAffine(track, rotation_matrix, size, flags=cv2.INTER_CUBIC) | |
count = 0 | |
h1 = ROOT.TH1D("h","rot_{0};x[mm]".format(angle),532, -10, 522) | |
h1.SetMaximum(200) | |
for yoko in range(img_rot.shape[0]): | |
for tate in range(img_rot.shape[1]): | |
bri = img_rot[yoko,tate] | |
if bri == 1: | |
xp = float(tate) | |
h1.Fill(xp) | |
h1.Draw() | |
# c1.Print("{0}.gif+10".format(aaa)) | |
''' | |
print 'x:{0} bri:{1}'.format(tate,bri) | |
##ここから下は、アフィン変換によって画像を回転させる関数である。 | |
center = tuple(np.array([center_x, center_y])) | |
# 画像サイズの取得(横, 縦) | |
size = tuple(np.array([track.shape[1], track.shape[0]])) | |
# 回転させたい角度 | |
# ラジアンではなく角度(°) | |
# 回転変換行列の算出 | |
rotation_matrix = cv2.getRotationMatrix2D(center, angle, scale) | |
# アフィン変換 | |
img_rot = cv2.warpAffine(track, rotation_matrix, size, flags=cv2.INTER_CUBIC) | |
#for tate in range(img_rot.shape[0]): | |
count = 0 | |
h1 = ROOT.TH1D("h","rot_{0};x[mm]".format(angle),532, -10, 522) | |
for yoko in range(img_rot.shape[0]): | |
for tate in range(img_rot.shape[1]): | |
bri = img_rot[yoko,tate] | |
if bri == 1: | |
print 'x:{0} bri:{1}'.format(tate,bri) | |
xp = float(tate) | |
h1.Fill(xp) | |
h1.Draw() | |
c1.Print("{0}.gif+100".format(aaa)) | |
''' | |
''' | |
for tate in range(img_rot.shape[1]): | |
bri = img_rot[220,tate] | |
print 'x:{0} bri:{1}'.format(tate,bri) | |
if bri == 1: | |
xp = float(tate) | |
h1.Fill(xp) | |
count += 1 | |
print count | |
''' | |
''' | |
track = track.rotate(45) | |
#cuts = int(math.floor((width + height) / math.sqrt(2))) | |
# 中央座標を計算して、必要な矩形を切り出す | |
pos = int(100) | |
bimimg = track.crop( (pos, pos, pos + 200, pos + 200) ) | |
''' | |
cv2.imshow('bigimg', track * 255) | |
cv2.imshow('big', img_rot * 255) | |
#cv2.imshow('big', bimimg ) | |
cv2.waitKey(0) | |
cv2.destroyAllWindows() | |
#c1.Print('GTR___.png') | |
''' | |
import matplotlib as mpl | |
from mpl_toolkits.mplot3d import Axes3D | |
import numpy as np | |
import matplotlib.pyplot as plt | |
(X,Y,Z) = np.mgrid[-10:10:25j, -10:10:25j, -10:10:10j] | |
col = np.random.rand(25,25,10) | |
fig = plt.figure(1) | |
fig.clf() | |
ax = Axes3D(fig) | |
ax.scatter(X,Y,Z, s = 5 ,c=col) | |
plt.draw() | |
plt.show() | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment