Example #1
0
def _load_holos():
    folder = 'data/Polystyrene2-4um-60xWater-042919/processed-128-thin/'
    file0 = 'im0001.tif'
    file1 = 'im0036.tif'
    holo0 = hp.load(folder + file0)
    holo1 = hp.load(folder + file1)
    return holo0.values.squeeze(), holo1.values.squeeze()
Example #2
0
def loadHolo():
    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
Example #3
0
def myHolo():
    ''' my holographic setup, which I think works since we use plane waves '''

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

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

    holo = obj - ref

    rec = hp.propagate(holo, np.linspace(2.5e-2, 7.5e-2, 200))

    return rec
Example #4
0
def jericho():
    ''' using Dr. Jericho's setup and images, currently doesn't work.
        I think this is because Jericho using a spherical wave. '''

    optics = hp.core.Optics(wavelen=405e-9, index=1.33, polarization=[1.0, 0.0])

    obj = hp.load('jerichoObject.bmp', spacing=6e-6, optics=optics)
    ref = hp.load('jerichoRef.bmp', spacing=6e-6, optics=optics)

    holo=obj-ref

    #rec = hp.propagate(holo, np.linspace(200e-6, 300e-6, 10))
    rec = hp.propagate(holo, np.linspace(12.5e-3, 13e-3, 20))

    return rec
Example #5
0
 def test_save_and_open(self):
     n = Uniform(0, 1)
     r = Uniform(0, np.pi / 2)
     spheres = [Sphere(n=n, r=r, center=[i, i, i]) for i in range(3)]
     spheres = Spheres(spheres)
     expected_keys = spheres.parameters.keys()
     with tempfile.TemporaryDirectory() as tempdir:
         hp.save(tempdir + '/test.out', spheres)
         spheres = hp.load(tempdir + '/test.out')
     self.assertEqual(spheres.parameters.keys(), expected_keys)
Example #6
0
def myHolo():
    ''' my holographic setup, which I think works since we use plane waves '''

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

    #obj = hp.load('tryit.png', spacing=7.6e-6, optics=optics)
    #ref = hp.load('ref.png', spacing=7.6e-6, optics=optics)

    obj = hp.load('fibreBright.png', spacing=7.6e-6, optics=optics)
    ref = hp.load('refBright.png', spacing=7.6e-6, optics=optics)

    #obj = hp.load('singleBright.png', spacing=7.6e-6, optics=optics)
    #ref = hp.load('singleRef.png', spacing=7.6e-6, optics=optics)

    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
Example #7
0
def fastload_silica_sedimentation_data(size=HOLOGRAM_SIZE, recenter=True):
    camera_resolution = 5.6983  # * 1.5 # px / um
    metadata = {
        'spacing': 1 / camera_resolution,
        'medium_index': 1.33,
        'illum_wavelen': .660,
        'illum_polarization': (1, 0)
    }
    folder = 'data/Silica1um-60xWater-021519/processed-{}'.format(size)
    if recenter is False: folder += '-uncentered'
    folder = os.path.join(HERE, folder)
    paths = [
        os.path.join(folder + '/im' + zfill(num) + '.h5') for num in range(100)
    ]
    data = [hp.load(path) for path in paths]
    return data
Example #8
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
Example #9
0
from __future__ import division,print_function
import holopy as hp
import numpy as np
import matplotlib.pyplot as plt

''' my holographic setup, which I think works since we use plane waves '''

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? '''
Example #10
0
    numpy.random.randn(im_size, im_size), gauss_width)

holo = holopy.model.tmatrix_trimer.forward_holo(im_size, optics_info, 1.59,
                                                1.59, 1.59, .00001, .00001,
                                                .00001, .5e-6, .5e-6, .5e-6,
                                                6e-6, 6e-6, 7e-6, .6, 45, 10,
                                                0.0)
holo = holo + noise_factor * noise
holo = holo * 255. / holo.max()
out_name = 'image0003.npy'
numpy.save(out_name, holo.astype('uint8'))

#trimer reconstructions
image_path = 'image0003.npy'
opts = 'optical_train3.yaml'
im = holopy.load(image_path, optics=opts)
rec_im = holopy.reconstruct(im, 4e-6)
rec_im = abs(rec_im[:, :, 0, 0] * scipy.conj(rec_im[:, :, 0, 0]))
rec_im = np.around(
    (rec_im - rec_im.min()) / (rec_im - rec_im.min()).max() * 255)
out_name = 'recon_4.npy'
numpy.save(out_name, rec_im.astype('uint8'))

rec_im = holopy.reconstruct(im, 7e-6)
rec_im = abs(rec_im[:, :, 0, 0] * scipy.conj(rec_im[:, :, 0, 0]))
rec_im = np.around(
    (rec_im - rec_im.min()) / (rec_im - rec_im.min()).max() * 255)
out_name = 'recon_7.npy'
numpy.save(out_name, rec_im.astype('uint8'))

rec_im = holopy.reconstruct(im, 10e-6)
Example #11
0
from __future__ import division,print_function
import holopy as hp
import numpy as np
import matplotlib.pyplot as plt
from mayavi import mlab

# setting up optics
#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()
Example #12
0
from holopy.core import load
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D

lamb=0.632
ind=1
#one='withObject1.png'
img='holoTest.png'
#two='withoutObject1.png'
pixels=6.8

optics = hp.core.Optics(lamb, ind,
                        polarization=[1.0, 0.0])

holo = hp.load(img, spacing = pixels,  optics = optics)
rec_vol = propagate(holo, linspace(0.01, 1, 7))

a=rec_vol.real
xSize=rec_vol.shape[0]
ySize=rec_vol.shape[1]
zSize=rec_vol.shape[2]

x=[i for i in xrange(xSize)]
y=[i for i in xrange(ySize)]


def slices(b):
    z=[]
    for i in x:
        for j in y:
im_size = 100
optics_info = holopy.optics.Optics(wavelen = 658e-9, index = 1.33, pixel_scale = 0.1e-6)
noise_factor = 0.04 # noise factor: fraction of smoothed gaussian noise that's added
gauss_width = 1.
noise = scipy.ndimage.filters.gaussian_filter(numpy.random.randn(im_size, im_size), gauss_width)

holo = holopy.model.tmatrix_trimer.forward_holo(im_size,optics_info,1.59,1.59,1.59,.00001,.00001,.00001,.5e-6,.5e-6,.5e-6,6e-6,6e-6,7e-6,.6,45,10,0.0)
holo = holo + noise_factor * noise
holo = holo*255./holo.max()
out_name = 'image0003.npy'
numpy.save(out_name, holo.astype('uint8'))

#trimer reconstructions
image_path = 'image0003.npy'
opts = 'optical_train3.yaml'
im = holopy.load(image_path,optics=opts)
rec_im = holopy.reconstruct(im, 4e-6)
rec_im = abs(rec_im[:,:,0,0] * scipy.conj(rec_im[:,:,0,0]))
rec_im = np.around((rec_im-rec_im.min())/(rec_im-rec_im.min()).max()*255)
out_name = 'recon_4.npy'
numpy.save(out_name, rec_im.astype('uint8'))

rec_im = holopy.reconstruct(im, 7e-6)
rec_im = abs(rec_im[:,:,0,0] * scipy.conj(rec_im[:,:,0,0]))
rec_im = np.around((rec_im-rec_im.min())/(rec_im-rec_im.min()).max()*255)
out_name = 'recon_7.npy'
numpy.save(out_name, rec_im.astype('uint8'))

rec_im = holopy.reconstruct(im, 10e-6)
rec_im = abs(rec_im[:,:,0,0] * scipy.conj(rec_im[:,:,0,0]))
rec_im = np.around((rec_im-rec_im.min())/(rec_im-rec_im.min()).max()*255)
Example #14
0
    # false.  Multiplying by this boolean matrix masks the array.
    g = g*(root>=0)

    if cfsp > 0:
        g = g**cfsp

    if squeeze:
        return np.squeeze(g)
    else:
        return g


magnification = 60
Spacing = 6.8/magnification
optics = hp.core.Optics(wavelen=.66, index=1.33, polarization=[1.0, 0.0])
obj = hp.load('image0100.tif', spacing=Spacing, optics=optics)

d = np.linspace(100,200,10)


m, n = np.ogrid[[slice(-dim/(2*ext), dim/(2*ext), dim*1j) for
                     (dim, ext) in zip(obj.shape[:2], obj.extent[:2])]]


d = np.array([d])
wavelen = obj.optics.med_wavelen
d = d.reshape([1, 1, d.size])

root = 1.+0j-(wavelen*n)**2 - (wavelen*m)**2
root *= (root >= 0)
Example #15
0
def load_gold_example_data():
    return normalize(hp.load(hp.core.io.get_example_data_path('image0001.h5')))
Example #16
0
import os
import matplotlib
matplotlib.use('Agg')
from pylab import *
from scipy.ndimage import measurements
import numpy as np
import matplotlib.pyplot as plt

import holopy as hp
from holopy.scattering import calc_holo, Sphere, calc_field, calc_intensity, calc_cross_sections
from holopy.scattering import Spheres
from holopy.scattering import Cylinder

from holopy.core.io import get_example_data_path
imagepath = get_example_data_path('image0002.h5')
exp_img = hp.load(imagepath)
"""
Qui se vuoi fissare due posizioni specifiche
"""
sphere1 = Sphere(center=(20, 20, 7), n=1.59, r=0.3)  #all in micro m units
sphere2 = Sphere(center=(25.6, 25.6, 7), n=1.59, r=0.3)
collection = Spheres([sphere1, sphere2])
medium_index = 1.33
illum_wavelength = 0.660
illum_polarization = (1, 0)
detector = hp.detector_grid(shape=512, spacing=0.1)  #spacing=pix size

holo = calc_holo(detector, collection, medium_index, illum_wavelength,
                 illum_polarization)

hp.show(holo)
Example #17
0
# initial guess
scaling_alpha = .6
radius = .85e-6
n_particle_real = 1.59
n_particle_imag = 1e-4
x = .576e-05
y = .576e-05
z = 15e-6

path = os.path.abspath(holopy.__file__)
path = string.rstrip(path, chars='__init__.pyc')+'tests/exampledata/'

# load the target file
# be sure to normalize, or fit will fail
holo = normalize(holopy.load(path + 'image0001.npy'))

# or fit a calculated hologram
#holo = mie.forward_holo(100, optics, gold_single[0], gold_single[1],
#                        gold_single[2], gold_single[3],
#                        gold_single[4], gold_single[5], gold_single[6])

# THIS IS IMPORTANT!
# specify typical orders of magnitude of variables passed to forward
# function through 'scale'.  This is so all variables passed to the
# forward function will be order(1), which is important for certain
# solvers that implicitly assume this.  If we don't do this, the
# solver might try to calculate a derivative by making an order(1)
# change in, say, the radius, which would stymie the forward function
# as it takes forever to calculate Mie scattering from a 1-meter
# large bead.
Example #18
0
def TestsobHypot(rec):

    x=ndimage.sobel(abs(rec)**2,axis=0, mode='constant')
    y=ndimage.sobel(abs(rec)**2,axis=1, mode='constant')
    hype = np.hypot(x,y)
    hype = hype.mean(axis=0).mean(axis=0)

    index = hype.argmax()
    return index

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

magnification = 60
Spacing = 6.8 / magnification

obj = hp.load('image0100.tif', spacing=Spacing, optics=optics)
#obj = hp.load('image0001.tif', spacing=Spacing, optics=optics)
#obj = hp.load('image0020.tif', spacing=Spacing, optics=optics)
ref = hp.load('../image0156.tif', spacing=Spacing, optics=optics)

holo = obj - ref

rec = hp.propagate(holo, np.linspace(475, 505, 20))

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

hp.show(rec)
plt.show()

a, b, c = rec.shape