Esempio n. 1
0
def test_reconstruction():
    im = get_example_data('image0003')
    rec = propagate(im, 4e-6)
    verify(rec, 'recon_single')

    rec = propagate(im, [4e-6, 7e-6, 10e-6])
    verify(rec, 'recon_multiple')
Esempio n. 2
0
def test_propagate_0_distance():
    im = get_example_data('image0003')
    rec = propagate(im, 0)
    # propagating no distance should leave the image unchanged
    assert_obj_close(im, rec)

    rec = propagate(im, [0, 3e-6])
    verify(rec, 'recon_multiple_with_0')
Esempio n. 3
0
    def slideZ(self, value):
        #using reconstructions-- better to use electric field?
        '''
        When z is changed, instead of recomputing the hologram, we
        use the shortcut of reconstructing the last computed hologram.
        '''
        source = self.sender()

        start = time.time()

        if self.lastZ == self.lcd3.value():
            self.holo = self.lastholo

        if self.lastZ < self.lcd3.value():
            self.holo = self.lastholo
            self.warning.setText(
                'Press calculate once you have all your parameters set')

        if self.lastZ > self.lcd3.value(
        ):  #reconstructing a plane between hologram and object
            self.holo = np.abs(
                propagate(self.lastholo, -self.lcd3.value() + self.lastZ))
            self.warning.setText('Reconstruction: hologram is approximate')

        end = time.time()

        #now take only the part that you want to display
        x = round(self.sld.value())
        y = round(self.sld2.value())
        selection = self.holo[256 - x:512 - x, 256 - y:512 - y]
        im = scipy.misc.toimage(selection)  #PIL image

        #https://github.com/shuge/Enjoy-Qt-Python-Binding/blob/master/image/display_img/pil_to_qpixmap.py
        #myQtImage = ImageQt(im)
        #qimage = QtGui.QImage(myQtImage)
        if im.mode == "RGB":
            pass
        elif im.mode == "L":
            im = im.convert("RGBA")
        data = im.tostring('raw', "RGBA")
        qim = QtGui.QImage(data, 256, 256, QtGui.QImage.Format_ARGB32)
        pixmap = QtGui.QPixmap.fromImage(qim)

        myScaledPixmap = pixmap.scaled(QtCore.QSize(400, 400))

        self.label.setPixmap(myScaledPixmap)
        #self.label.setGeometry(10, 10, 400, 400)
        #self.label.setScaledContents(True)

        self.timer.setGeometry(420, 400, 150, 30)
        self.timer.setText('Calc. Time: ' + str(round(end - start, 4)) + ' s')
        self.timer.setAlignment(QtCore.Qt.AlignBottom | QtCore.Qt.AlignCenter)

        sphere2 = Sphere(n=self.lcd5.value() + .0001j,
                         r=self.lcd4.value(),
                         center=(self.lcd.value(), self.lcd2.value(),
                                 self.lcd3.value()))

        self.sphObject.setText(repr(sphere2))
    def slideZ(self, value):
        # using reconstructions-- better to use electric field?
        """
        When z is changed, instead of recomputing the hologram, we
        use the shortcut of reconstructing the last computed hologram.
        """
        source = self.sender()

        start = time.time()

        if self.lastZ == self.lcd3.value():
            self.holo = self.lastholo

        if self.lastZ < self.lcd3.value():
            self.holo = self.lastholo
            self.warning.setText("Press calculate once you have all your parameters set")

        if self.lastZ > self.lcd3.value():  # reconstructing a plane between hologram and object
            self.holo = abs(propagate(self.lastholo, -self.lcd3.value() + self.lastZ))
            self.warning.setText("Reconstruction: hologram is approximate")

        end = time.time()

        # now take only the part that you want to display
        x = round(self.sld.value())
        y = round(self.sld2.value())
        selection = self.holo[256 - x : 512 - x, 256 - y : 512 - y]
        im = toimage(selection)  # PIL image

        # https://github.com/shuge/Enjoy-Qt-Python-Binding/blob/master/image/display_img/pil_to_qpixmap.py
        # myQtImage = ImageQt(im)
        # qimage = QtGui.QImage(myQtImage)
        if im.mode == "RGB":
            pass
        elif im.mode == "L":
            im = im.convert("RGBA")
        data = im.tostring("raw", "RGBA")
        qim = QtGui.QImage(data, 256, 256, QtGui.QImage.Format_ARGB32)
        pixmap = QtGui.QPixmap.fromImage(qim)

        myScaledPixmap = pixmap.scaled(QtCore.QSize(400, 400))

        self.hologram.setPixmap(myScaledPixmap)
        # self.hologram.setGeometry(10, 10, 400, 400)
        # self.hologram.setScaledContents(True)

        self.timer.setGeometry(420, 400, 150, 30)
        self.timer.setText("Calc. Time: " + str(round(end - start, 4)) + " s")
        self.timer.setAlignment(QtCore.Qt.AlignBottom | QtCore.Qt.AlignCenter)

        sphere2 = Sphere(
            n=self.lcd5.value() + 0.0001j,
            r=self.lcd4.value(),
            center=(self.lcd.value(), self.lcd2.value(), self.lcd3.value()),
        )

        self.sphObject.setText(repr(sphere2))
Esempio n. 5
0
def test_propagate_e_field():
    e = calc_field(detector_grid(100, 0.1),
                   Sphere(1.59, .5, (5, 5, 5)),
                   illum_wavelen=0.66,
                   medium_index=1.33,
                   illum_polarization=(1, 0),
                   theory=Mie(False))

    prop_e = propagate(e, 10)
    verify(prop_e, 'propagate_e_field')
    def slideZ(self, sphere, schema): 
        '''
        When z is changed, and reconstruction is selected, do reconstruction.
        '''
        if sphere.parameters == self.oldReconParameters and repr(schema) == repr(self.oldReconSchema):
            self.holo = self.oldReconHolo
        else:
            start = time.time()

            if self.lastZ == self.lcd3.value():
                self.holo = self.lastholo

            if self.lastZ < self.lcd3.value():
                self.holo = self.lastholo
                self.warning.setText('Cannot reconstruct to larger z')

            if self.lastZ > self.lcd3.value(): #reconstructing a plane between hologram and object
                self.holo = np.abs(propagate(self.lastholo, -self.lcd3.value()+self.lastZ))
                self.warning.setText('Reconstruction: hologram is approximate')

            end = time.time()
            self.oldReconHolo = self.holo
            self.oldReconParameters = sphere.parameters
            self.oldReconSchema = schema
Esempio n. 7
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)
Esempio n. 8
0
def test_gradient_filter():
    im = get_example_data('image0003')
    rec = propagate(im, [4e-6, 7e-6, 10e-6], gradient_filter=1e-6)
    verify(rec, 'recon_multiple_gradient_filter')
Esempio n. 9
0
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:
            z.append(a[i][j][b])
Esempio n. 10
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)
Esempio n. 11
0
File: bb.py Progetto: RobieH/honours
from __future__ import print_function
import numpy as np
import holopy as hp
from holopy.propagation import propagate
from holopy.core import load
import matplotlib.pyplot as plt
import time

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

holo = load("jerichoObject.bmp", spacing=6e-6, optics=optics)
bg = load("jerichoRef.bmp", spacing=6e-6, optics=optics)

holo = holo - bg

rec_vol = propagate(holo, np.linspace(245e-6, 250e-6, 5))

plt.ion()
fig = plt.figure()
ax = fig.gca()
for i in xrange(rec_vol.shape[2]):
    print(i)
    #        name='figure%d.png'%(i,)
    #        plt.savefig(name,bbox_inches=0)
    plt.clf()

    plt.imshow(rec_vol[..., i].real, cmap=plt.cm.Greys_r)
    fig.canvas.draw()
    time.sleep(1)