Exemple #1
0
def test_show():
    d = get_example_data('image0001')
    try:
        hp.show(d)
    except RuntimeError:
        # this occurs on travis since there is no display
        raise SkipTest()
    with warnings.catch_warnings():
        warnings.simplefilter('ignore'), (DeprecationWarning, UserWarning)
        plt.savefig(tempfile.TemporaryFile(suffix='.pdf'))
Exemple #2
0
def test_show():
    d = get_example_data('image0001')
    try:
        hp.show(d)
    except RuntimeError:
        # this occurs on travis since there is no display
        raise SkipTest()    
    with warnings.catch_warnings():
        warnings.simplefilter('ignore'),  (DeprecationWarning, UserWarning)
        plt.savefig(tempfile.TemporaryFile(suffix='.pdf'))
Exemple #3
0
def calcolo_hologram_BINNING(cartella, name, pixel_size, lim, binsize,
                             pixcombine):
    """
    Open the image with the correspective path, it calculates the center of the
    hologram and it prints it on the console.
    Then cut the image with a fixed dimension around the center. So the new 
    center of the image is fixed.
    Finally it rebins the image.
    
    Warning: to find the center you have to open the image with holopy function.
    But you can't rebbined DataArray. So you had to open it also with PIL.
    !!!!Maybe you can correct this in a second time!!!!
    Parameters
    ----------
    cartella: str
        Name of the folder of the image
    name: str
        Number within the name of the image (without type)
    pixel_size: float
        Value of the pixel size (um)
    lim: int
        Value of the half shape of the new matrix. It will be the new center
    binsize: int
        Value of the new reshape
    pixcombine: str
        The method to combine the pixels with. Choices are sum, mean and median
        
    Returns
    -------
    data_holo: :class:`.Image` or :class:`.VectorGrid`
        Data reshaped of the hologram
    """
    raw_holo = hp.load_image("../Campioni/Flusso/" + cartella +
                             "/img_correct/img_" + name + ".tiff",
                             spacing=pixel_size)
    hp.show(raw_holo)
    plt.show()

    im = Image.open("../Campioni/Flusso/" + cartella + "/img_correct/img_" +
                    name + ".tiff").convert("L")
    I = np.asarray(im)

    centro = center_find(raw_holo, centers=1, threshold=0.3, blursize=6.0)
    print(centro)
    data_holo = I[int(centro[0] - lim):int(centro[0] + lim),
                  int(centro[1] - lim):int(centro[1] + lim)]

    data_holo = rebin(data_holo, ((binsize, binsize)), pixcombine)
    lim = lim / 2

    hp.show(data_holo)
    plt.show()

    return (data_holo)
Exemple #4
0
def myHolo():

    optics = hp.core.Optics(wavelen=.632, index=1.33, polarization=[1.0, 0.0])

    #magnification = 40
    #Spacing = 6.8 / magnification
    Spacing = 0.1

    obj = hp.load('cgh.png', spacing=Spacing, optics=optics)
    #ref = hp.load('image0146.tif', spacing=Spacing, optics=optics)

    #holo = obj - ref
    holo = obj

    hp.show(holo)
    plt.show()

    rec = hp.propagate(holo, np.linspace(100, 150, 50))

    return rec
Exemple #5
0
def calcolo_hologram(cartella, name, pixel_size, lim):
    """
    Open the image with the correspective path, it calculates the center of the
    hologram and it prints it on the console.
    Then cut the image with a fixed dimension around the center. So the new 
    center of the image is fixed.
    Parameters
    ----------
    cartella: str
        Name of the folder of the image
    name: str
        Number within the name of the image (without type)
    pixel_size: float
        Value of the pixel size (um)
    lim: int
        Value of the half shape of the new matrix. It will be the new center 
        
    Returns
    -------
    data_holo: :class:`.Image` or :class:`.VectorGrid`
        Data reshaped of the hologram
    """
    raw_holo = hp.load_image("../Campioni/Flusso/" + cartella +
                             "/img_correct/img_" + name + ".tiff",
                             spacing=pixel_size)

    centro = center_find(raw_holo, centers=1, threshold=0.3, blursize=6.0)
    print(centro)
    data_holo = raw_holo[0,
                         int(centro[0] - lim):int(centro[0] + lim),
                         int(centro[1] - lim):int(centro[1] + lim)]

    hp.show(data_holo)
    plt.show()

    return (data_holo)
Exemple #6
0
optics = hp.core.Optics(wavelen=.66, index=1.33, polarization=[1.0, 0.0])

magnification = 40
Spacing = 6.8 / magnification

obj = hp.load('image0148.tif', spacing=Spacing, optics=optics)
ref = hp.load('image0146.tif', spacing=Spacing, optics=optics)

focus = hp.load('image0147.tif', spacing=Spacing, optics=optics)

holo = obj - ref

rec = hp.propagate(holo, np.linspace(1, 100, 50))

hp.show(focus)
plt.show()

hp.show(holo)
plt.show()

hp.show(rec)
plt.show()

''' 3D plotting - useful? '''
#from mayavi import mlab
#mlab.contour3d(recInt)
##    mlab.pipeline.volume(mlab.pipeline.scalar_field(newImg))
#mlab.axes(x_axis_visibility=True,y_axis_visibility=True,z_axis_visibility=True)
#mlab.outline()
#mlab.show()
Exemple #7
0
import holopy as hp
from holopy.scattering.scatterer import Axisymmetric, Spheroid
from holopy.core import ImageSchema, Optics
from holopy.scattering.theory import Tmatrix, DDA
from holopy.core.math import rotation_matrix

schema = ImageSchema(shape = 200, spacing = .1,
                     optics = Optics(wavelen = .660, index = 1.33,
                                     polarization = [1,0]))

#ps = Spheroid(n = 1.585, r = [.4,1.5], rotation=[pi/2, 2], center = [10,10,20])
#holo = DDA.calc_holo(ps,schema)
#hp.show(holo)

ps = Axisymmetric(n = 1.585, r = [.4,1.5], rotation=[pi/2, 2], center = [10,10,20])
holo = Tmatrix.calc_holo(ps,schema)
hp.show(holo)

import holopy as hp
import numpy as np
from holopy.core.io import get_example_data_path
from holopy.propagation import ps_propagate
from scipy.ndimage.measurements import center_of_mass

imagepath = get_example_data_path('ps_image01.jpg')
bgpath = get_example_data_path('ps_bg01.jpg')
L = 0.0407 # distance from light source to screen/camera
cam_spacing = 12e-6 # linear size of camera pixels
mag = 9.0 # magnification
npix_out = 1020 # linear size of output image (pixels)
zstack = np.arange(1.08e-3, 1.18e-3, 0.01e-3) # distances from camera to reconstruct

holo = hp.load_image(imagepath, spacing=cam_spacing, illum_wavelen=406e-9, medium_index=1) # load hologram
bg = hp.load_image(bgpath, spacing=cam_spacing) # load background image
holo = hp.core.process.bg_correct(holo, bg+1, bg) # subtract background (not divide)
beam_c = center_of_mass(bg.values.squeeze()) # get beam center
out_schema = hp.core.detector_grid(shape=npix_out, spacing=cam_spacing/mag) # set output shape

recons = ps_propagate(holo, zstack, L, beam_c, out_schema) # do propagation
hp.show(abs(recons[:,350:550,450:650])) # display result
Exemple #9
0
import numpy as np
import holopy as hp
from holopy.core.io import get_example_data_path, load_average
from holopy.core.process import bg_correct

imagepath = get_example_data_path('image01.jpg')
raw_holo = hp.load_image(
    imagepath,
    spacing=0.0851,
    medium_index=1.33,
    illum_wavelen=0.66,
)
bgpath = get_example_data_path(['bg01.jpg', 'bg02.jpg', 'bg03.jpg'])
bg = load_average(bgpath, refimg=raw_holo)
holo = bg_correct(raw_holo, bg)

zstack = np.linspace(0, 20, 11)
rec_vol = hp.propagate(holo, zstack)
hp.show(rec_vol)
Exemple #10
0
#optics = hp.core.Optics(wavelen=.405, index=1.33, polarization=[1.0, 0.0])

optics = hp.core.Optics(wavelen=.635, index=1.33, polarization=[1.0, 0.0])

# loading the images
#obj = hp.load('jerichoObject.bmp',spacing=6,optics=optics)
#ref = hp.load('jerichoRef.bmp',spacing=6,optics=optics)

obj = hp.load('fibre1.png',spacing=7.6,optics=optics)
ref = hp.load('refFibre1.png',spacing=7.6,optics=optics)

# contrast image
holo=obj-ref

# reconstruction, same image for all slices though
#rec = hp.propagate(holo, np.linspace(200,13e7,10))
rec = hp.propagate(holo, np.linspace(3.5e4,5.5e4,100))

# intensity so pyplot can plot it
recInt=abs(rec)*abs(rec)

hp.show(recInt)
plt.show()

''' 3D plotting - useful? '''
#mlab.contour3d(recInt)
##    mlab.pipeline.volume(mlab.pipeline.scalar_field(newImg))
#mlab.axes(x_axis_visibility=True,y_axis_visibility=True,z_axis_visibility=True)
#mlab.outline()
#mlab.show()
Exemple #11
0
from numpy import linspace
import holopy as hp
from holopy.core import Optics
from holopy.propagation import propagate
from holopy.core.tests.common import get_example_data
from holopy.core import load

#holo = get_example_data('image0001.yaml')
#rec_vol = propagate(holo, linspace(4e-6, 10e-6, 7))
#hp.show(rec_vol)

optics = hp.core.Optics(wavelen=.660, index=1.33,
                        polarization=[1.0, 0.0])
holo = hp.core.load('newredblood2.png',spacing=7.6,optics=optics)
rec_vol = propagate(holo, linspace(1e-3,5e-2,100))
hp.show(holo)
hp.show(rec_vol)
Exemple #12
0
#medium_index = 1.33
#illum_wavelen = 0.66
#illum_polarization = (1,0)
#detector = hp.detector_grid(shape = 512, spacing = 0.0851)
holo = hp.load_image('outfilename8febb.tif', spacing = 0.0851, medium_index = 1.33, illum_wavelen = 0.66, )


"""
2)PROPAGATION
"""

N=512
z = np.linspace(0,20,300)
rec_vol = hp.propagate(holo, z)
phase=np.angle(rec_vol)

for i in range(0,len(z)):
    p=np.angle(np.e**(-1j*2*np.pi*z[i]/(0.66/1.33)))*np.ones((N,N))
    diff=phase[i]-p
    diff[diff>np.pi]=0
    diff[diff<-np.pi]=0
    if np.isin(diff.any(),diff>2.5):
        hp.show(diff)
        plt.title(z[i])
 





Exemple #13
0
    optics = hp.core.Optics(wavelen=.66, index=1.33, polarization=[1.0, 0.0])

    magnification = 20
    Spacing = 6.8 / magnification

    obj = hp.load('P1000017.tiff', spacing=Spacing, optics=optics)
    ref = hp.load('P1000019.tiff', spacing=Spacing, optics=optics)

    holo = obj - ref

    return holo

holo = loadHolo()
#holo = holo[1100:1700,1200:1800]
rec = hp.propagate(holo, np.linspace(1500, 1600, 5))
#rec = hp.propagate(holo, 16000)

#hp.show(holo)
#plt.show()

hp.show(rec)
plt.show()

''' 3D plotting - useful? '''
#from mayavi import mlab
#mlab.contour3d(recInt)
##    mlab.pipeline.volume(mlab.pipeline.scalar_field(newImg))
#mlab.axes(x_axis_visibility=True,y_axis_visibility=True,z_axis_visibility=True)
#mlab.outline()
#mlab.show()
Exemple #14
0
def test_show():
    d = get_example_data('image0001.yaml')
    hp.show(d)
    with warnings.catch_warnings():
        warnings.simplefilter('ignore', DeprecationWarning)
        plt.savefig(tempfile.TemporaryFile(suffix='.pdf'))
Exemple #15
0
import holopy as hp
from holopy.core.io import get_example_data_path
imagepath = get_example_data_path('image01.jpg')
raw_holo = hp.load_image(imagepath, spacing = 0.0851)
hp.show(raw_holo)
Exemple #16
0
taus = empty((subtracted.shape[0],subtracted.shape[1],n_steps))
taus_ft = empty((subtracted.shape[0],subtracted.shape[1],n_steps))

for i in arange(0,n_steps):
    print('avg number ' + str(i+1) + ' of ' + str(n_steps))
    #average video into sections
    i_min = i*n_avg
    i_max = min((i+1)*n_avg, subtracted.shape[2]-delta_ts.max())
    sub_mean = mean(subtracted[:,:,i_min:i_max,:],2)
    sub_mean_ft = mean(subtracted_ft[:,:,i_min:i_max,:],2)

    #fit exponential curve to data
    amps[:,:,i], taus[:,:,i], amps_std, taus_std =  fpt.fit_px_for_tau(sub_mean, ts, norm_amps = True)
    amps_ft[:,:,i], taus_ft[:,:,i], amps_ft_std, taus_ft_std =  fpt.fit_px_for_tau(sub_mean_ft, ts, norm_amps = True)

hp.show(amps)
#savefig(outfolder+'amplitude.tif' )
hp.show(taus)
#savefig(outfolder+'tau.tif' )

'''hp.show(amps_ft)
savefig(outfolder+'amplitude_ft.tif' )
hp.show(taus_ft)
savefig(outfolder+'tau_ft.tif' )

hp.show(amps_std)
savefig(outfolder+'amplitude_std.tif' )
hp.show(taus_std)
savefig(outfolder+'tau_std.tif' )

hp.show(amps_ft_std)
from numpy import linspace
import holopy as hp
from holopy.core import Optics
from holopy.propagation import propagate
from holopy.core.tests.common import get_example_data
from holopy.core import load

holo = get_example_data('image0001.yaml')
rec_vol = propagate(holo, linspace(4e-6, 10e-6, 7))
hp.show(rec_vol)
Exemple #18
0
def test_show():
    d = get_example_data('image0001.yaml')
    hp.show(d)
    plt.savefig(tempfile.TemporaryFile(suffix='.pdf'))
import holopy as hp
from holopy.core.io import get_example_data_path
imagepath = get_example_data_path('image01.jpg')
raw_holo = hp.load_image(imagepath, spacing=0.0851)
hp.show(raw_holo)
Exemple #20
0
    holo = obj - ref

    ''' between 4 cm and 10 cm, should be about 5.5 cm '''
    #rec = hp.propagate(holo, np.linspace(4e-2, 10e-2, 200))
    rec = hp.propagate(holo, np.linspace(5e-2, 6e-2, 200))
    #rec = hp.propagate(holo, np.linspace(0.5e-2, 2e-2, 200))

    return rec

rec = myHolo()

recInt = abs(rec) * abs(rec)

print('Amplitude')
hp.show(recInt)
plt.show()

print('Imaginary')
hp.show(rec.imag)
plt.show()

print('Phase')
phase=np.arctan(rec.imag/rec.real)
#phase=np.unwrap(phase)
hp.show(phase)
#hp.show(np.angle(rec))
plt.show()

#import os
#os.chdir('saves/')
Exemple #21
0
import holopy as hp
from holopy.scattering.scatterer import Sphere
from holopy.scattering.theory import Mie
from holopy.core import ImageSchema, Optics
schema = ImageSchema(shape=100,
                     spacing=.1,
                     optics=Optics(wavelen=.660,
                                   index=1.33,
                                   polarization=[1, 0]))
cs = Sphere(center=(2.5, 5, 5), n = (1.59, 1.42),\
            r = (0.3, 0.6))
holo = Mie.calc_holo(cs, schema)
hp.show(holo)
Exemple #22
0
def test_show():
    d = get_example_data('image0001.yaml')
    hp.show(d)
    with warnings.catch_warnings():
        warnings.simplefilter('ignore', DeprecationWarning)
        plt.savefig(tempfile.TemporaryFile(suffix='.pdf'))