mirror of
https://github.com/cdtools-developers/cdtools.git
synced 2026-09-17 08:19:57 +02:00
Merge branch 'master' of github.mit.edu:Scattering/CDTools
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
import imageio
|
||||
|
||||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
class ImageSeries:
|
||||
|
||||
def __init__(self, images, crop,fps=None):
|
||||
self.images = images #list of images (numpy arrays), saved itself as a numpy array
|
||||
self.L = len(self.images)
|
||||
self.x1, self.x2, self.y1, self.y2 = crop #(x1,y1) and (x2,y2) are cropping coords
|
||||
self.crimages = []
|
||||
for i in range(self.L):
|
||||
self.crimages.append(self.images[i][self.x1:self.x2, self.y1:self.y2])
|
||||
self.crimages = np.array(self.crimages)
|
||||
self.fps = fps
|
||||
|
||||
def show_frame(self,t): #t = time to show
|
||||
if 0 <= t <= self.L:
|
||||
plt.imshow(self.crimages[t],interpolation="none")
|
||||
plt.show()
|
||||
return
|
||||
|
||||
def save_vid(self, filename, secspersec):
|
||||
imageio.mimwrite(filename, self.crimages, fps=self.fps*secspersec)
|
||||
|
||||
def waterfall(self,x,y):
|
||||
if x == None:
|
||||
#plot row y=y over time
|
||||
return self.crimages[:,:,y]
|
||||
elif y == None:
|
||||
return np.transpose(self.crimages[:,x,:])
|
||||
|
||||
def plot_waterfall(self,x,y,tint=None):
|
||||
waterfall = self.waterfall(x,y)
|
||||
if x == None:
|
||||
#plot col y over time
|
||||
fig = plt.figure()
|
||||
W = fig.add_subplot(111)
|
||||
W.imshow(waterfall,interpolation="none")
|
||||
if tint:
|
||||
plt.yticks(np.arange(0,self.L,self.fps*tint),np.arange(0,self.L/self.fps,tint))
|
||||
W.set_title("waterfall plot of row y = " + str(y))
|
||||
W.set_ylabel("time [s]")
|
||||
plt.show()
|
||||
return
|
||||
elif y == None:
|
||||
#plot col x=x over time
|
||||
fig = plt.figure()
|
||||
W = fig.add_subplot(111)
|
||||
W.imshow(waterfall,interpolation="none")
|
||||
if tint:
|
||||
plt.xticks(np.arange(0,self.L,self.fps*tint),np.arange(0,self.L/self.fps,tint))
|
||||
W.set_title("waterfall plot of col x = " + str(x))
|
||||
W.set_xlabel("time [s]")
|
||||
plt.show()
|
||||
return
|
||||
return
|
||||
|
||||
def Ipixel(self,pixel):
|
||||
px,py = pixel
|
||||
return self.crimages[:,px,py]
|
||||
|
||||
def plot_Ipixel(self,pixel,description=""):
|
||||
I = self.Ipixel(pixel)
|
||||
fig = plt.figure()
|
||||
f1 = fig.add_subplot(111)
|
||||
f1.set_title("I(t) for pixel" + str(pixel) + " (" + description + ")")
|
||||
f1.set_xlabel("time [s]")
|
||||
f1.plot(np.arange(0,self.L/self.fps,1/self.fps),I)
|
||||
plt.show()
|
||||
return
|
||||
|
||||
def fftIpixel(self,pixel):
|
||||
I = self.Ipixel(pixel)
|
||||
IfreqA = np.fft.fft(I)/self.L
|
||||
Ifreq = np.fft.fftfreq(self.L,d=(1/self.fps))
|
||||
return(Ifreq, IfreqA)
|
||||
|
||||
def plot_fftIpixel(self,pixel):
|
||||
Ifreq, IfreqA = self.fftIpixel(pixel)
|
||||
fig = plt.figure()
|
||||
f1 = fig.add_subplot(111)
|
||||
f1.set_title("FFT for pixel" + str(pixel))
|
||||
f1.set_xlabel("frequency [1/s]")
|
||||
f1.plot(Ifreq, abs(IfreqA))
|
||||
plt.show()
|
||||
return
|
||||
|
||||
def g2(self,pixel):
|
||||
I = self.Ipixel(pixel)
|
||||
g2 = []
|
||||
avgsq = np.mean(I)**2
|
||||
for tau in range(len(I)-1):
|
||||
if tau == 0:
|
||||
dotp = 0
|
||||
for t in range(len(I)):
|
||||
dotp += I[t]*I[t]
|
||||
g2.append(dotp/(len(I)*avgsq) )
|
||||
elif tau != 0:
|
||||
dotp = 0
|
||||
for t in range(len(I)-tau):
|
||||
dotp += I[t]*I[t+tau]
|
||||
g2.append( dotp / (len(I[:-tau])*avgsq))
|
||||
g2 = np.array(g2)
|
||||
return g2
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
import imageio
|
||||
from PIL import Image, ImageSequence
|
||||
from debugging_mod import ImageSeries
|
||||
|
||||
|
||||
vid = Image.open('data_10_4/kiara_20fps_redlaser_vid.tif')
|
||||
|
||||
vidarray = []
|
||||
for i, page in enumerate(ImageSequence.Iterator(vid)):
|
||||
pg = np.array(page)
|
||||
vidarray.append(pg)
|
||||
vidarray = np.array(vidarray)
|
||||
|
||||
RedLaserExp = ImageSeries(vidarray, (430,606,590,766),fps=20) #cropping x1:x2, y1:y2
|
||||
|
||||
#with np.load('data_9_28/kiara_data_300sec_green') as data:
|
||||
# GreenLaserExp = ImageSeries(data['arr_0'], (500,676,580,756), fps=5)
|
||||
#crop to: x1=500, x2=676, y1=580, y2=756
|
||||
|
||||
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
#Note: human eye can see at c. 150 fps
|
||||
|
||||
#inner top right corner of disk (120,70)
|
||||
#inner top left corner of disk (66,63)
|
||||
#inner bottom left corner of disk (66,107)
|
||||
#inner bottom (87,118)
|
||||
#inner right (125, 86)
|
||||
|
||||
#pixel intensity plot: ---------------------------------------
|
||||
#RedLaserExp.plot_Ipixel((125,86),description="inner right")
|
||||
#RedLaserExp.plot_Ipixel((87,118),description="inner bottom")
|
||||
#RedLaserExp.plot_Ipixel((66,63),description="inner top left")
|
||||
|
||||
#pixel fft plot: --------------------------------------------
|
||||
#RedLaserExp.plot_fftIpixel((125,86))
|
||||
#RedLaserExp.plot_fftIpixel((87,118))
|
||||
#RedLaserExp.plot_fftIpixel((66,63))
|
||||
|
||||
#waterfall plot for row: -------------------------------------
|
||||
#RedLaserExp.plot_waterfall(None,118,tint=1)
|
||||
|
||||
#waterfall plot for col: -------------------------------------
|
||||
#RedLaserExp.plot_waterfall(66,None,tint=1)
|
||||
|
||||
#save a video: -----------------------------------------------
|
||||
#RedLaserExp.save_vid("redlaser_10-4_20fps_1x.mp4",1)
|
||||
Reference in New Issue
Block a user