예제 #1
0
def centerfind_xy_positions_silica(size=HOLOGRAM_SIZE, holonums=range(1000)):
    camera_resolution = 5.6983 * 1.5  # px / um
    metadata = {
        'spacing': 1 / camera_resolution,
        'medium_index': 1.33,
        'illum_wavelen': .660,
        'illum_polarization': (1, 0)
    }
    position = [650,
                587]  # leaves the particle in the hologram for most frames
    paths = [
        "data/Silica1um-60xWater-080619/raw0[x1.5]/im" + zfill(num, 4) + ".tif"
        for num in holonums
    ]
    refimg = hp.load_image(paths[0], **metadata)
    bkg = load_bkg("data/Silica1um-60xWater-080619/raw0[x1.5]/",
                   bg_prefix='bg',
                   refimg=refimg)
    dark = load_dark("data/Silica1um-60xWater-080619/raw0[x1.5]/",
                     df_prefix='dark',
                     refimg=refimg)
    all_positions = []
    for path in paths:
        this_holo, position = load_bgdivide_crop(path=path,
                                                 metadata=metadata,
                                                 particle_position=position,
                                                 bkg=bkg,
                                                 dark=dark,
                                                 size=size,
                                                 recenter=True)
        all_positions.append(tuple(position))
    return all_positions
예제 #2
0
def load_polystyrene_sedimentation_data(size=HOLOGRAM_SIZE,
                                        holonums=range(1000),
                                        recenter=True):
    camera_resolution = 5.6983  # px / um
    metadata = {
        'spacing': 1 / camera_resolution,
        'medium_index': 1.33,
        'illum_wavelen': .660,
        'illum_polarization': (1, 0)
    }
    position = [270, 370]  #  leaves all the particles mostly in the hologram
    paths = [
        "data/Polystyrene2-4um-60xWater-042919/raw/im" + zfill(num, 4) + ".tif"
        for num in holonums
    ]
    refimg = hp.load_image(paths[0], **metadata)
    bkg = load_bkg("data/Polystyrene2-4um-60xWater-042919/raw/",
                   bg_prefix='bg',
                   refimg=refimg)
    dark = load_dark("data/Polystyrene2-4um-60xWater-042919/raw/",
                     df_prefix='dark',
                     refimg=refimg)
    holos = []
    for path in paths:
        this_holo = load_bgdivide_crop(path=path,
                                       metadata=metadata,
                                       particle_position=position,
                                       bkg=bkg,
                                       dark=dark,
                                       size=size,
                                       recenter=recenter)[0]
        holos.append(this_holo)
    return holos
예제 #3
0
def load_bgdivide_crop_v2(
        path, metadata, particle_position, bkg, dark, channel=RGB_CHANNEL,
        size=HOLOGRAM_SIZE):
    data = hp.load_image(path, channel=channel, **metadata)
    data = bg_correct(data, bkg, dark)
    data = subimage(data, particle_position[::-1], size)
    data = normalize(data)
    return data
예제 #4
0
def load_bgdivide_crop(
        path, metadata, particle_position, bg_prefix="bg", df_prefix=None,
        channel=RGB_CHANNEL, size=HOLOGRAM_SIZE):
    data = hp.load_image(path, channel=channel, **metadata)
    bkg = load_bkg(path, bg_prefix, refimg=data)
    dark = None  # load_dark(path, df_prefix, refimg=data)
    data = bg_correct(data, bkg, dark)
    data = subimage(data, particle_position[::-1], size)
    data = normalize(data)
    return data
예제 #5
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)
예제 #6
0
def calc_holo_mieonly(center0, center1, center2, n, r, alpha):
    sph = Sphere(center=(center0, center1, center2), n=n, r=r)
    camera_resolution = 5.6983  # px / um
    metadata = {
        'spacing': 1 / camera_resolution,
        'medium_index': 1.33,
        'illum_wavelen': .660,
        'illum_polarization': (1, 0)
    }
    return calc_holo(hp.load_image('image0029.tif', **metadata),
                     sph,
                     scaling=alpha).values.squeeze()
예제 #7
0
    def __init__(self, data_filenames, metadata, particle_position,
                 background_prefix="bg", darkfield_prefix=None):
        self.data_filenames = list(data_filenames)
        self.metadata = metadata
        self.particle_position = particle_position
        self.background_prefix = background_prefix
        self.darkfield_prefix = darkfield_prefix

        self.root_folder = os.path.dirname(self.data_filenames[0])
        self._reference_image = hp.load_image(
            self.data_filenames[0], channel=RGB_CHANNEL, **self.metadata)
        self._background = self._load_background()
        self._darkfield = self._load_darkfield()
예제 #8
0
def load_example_data():
    imagepath = hp.core.io.get_example_data_path('image01.jpg')
    raw_holo = hp.load_image(imagepath,
                             spacing=0.0851,
                             medium_index=1.33,
                             illum_wavelen=0.66,
                             illum_polarization=(1, 0))
    bgpath = hp.core.io.get_example_data_path(
        ['bg01.jpg', 'bg02.jpg', 'bg03.jpg'])
    bg = hp.core.io.load_average(bgpath, refimg=raw_holo)
    holo = hp.core.process.bg_correct(raw_holo, bg)
    holo = hp.core.process.subimage(holo, [250, 250], 200)
    holo = hp.core.process.normalize(holo)
    return holo
예제 #9
0
def fastload_polystyrene_sedimentation_data(size=HOLOGRAM_SIZE, recenter=True):
    camera_resolution = 5.6983  # px / um
    metadata = {
        'spacing': 1 / camera_resolution,
        'medium_index': 1.33,
        'illum_wavelen': .660,
        'illum_polarization': (1, 0)
    }
    folder = 'data/Polystyrene2-4um-60xWater-042919/processed-{}'.format(size)
    if recenter is False: folder += '-uncentered'
    folder = os.path.join(HERE, folder)
    paths = [
        os.path.join(folder + '/im' + zfill(num) + '.tif')
        for num in range(1000)
    ]
    data = [hp.load_image(path, **metadata) for path in paths]
    return data
예제 #10
0
def load_silica_sedimentation_data(size=HOLOGRAM_SIZE,
                                   holonums=range(100),
                                   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)
    }
    position = [553,
                725]  # leaves the particle in the hologram for most frames
    paths = [
        "data/Silica1um-60xWater-021519/raw/image" + zfill(num, 4) + ".tif"
        for num in holonums
    ]
    refimg = hp.load_image(paths[0], **metadata)
    bkg = load_bkg("data/Silica1um-60xWater-021519/raw/",
                   bg_prefix='bg',
                   refimg=refimg)
    dark = load_dark("data/Silica1um-60xWater-021519/raw/",
                     df_prefix='dark',
                     refimg=refimg)
    holos = []
    all_positions = []
    new_pos = None
    for path in paths:
        this_holo, new_pos = load_bgdivide_crop(path=path,
                                                metadata=metadata,
                                                particle_position=position,
                                                bkg=bkg,
                                                dark=dark,
                                                size=size,
                                                recenter=recenter)
        holos.append(this_holo)
        if new_pos is not None:
            position = new_pos
            all_positions.append([tuple(new_pos)])
    return holos
예제 #11
0
def load_bgdivide_crop(path,
                       metadata,
                       particle_position,
                       bkg,
                       dark,
                       channel=RGB_CHANNEL,
                       size=HOLOGRAM_SIZE,
                       recenter=True):
    data = hp.load_image(path, channel=channel, **metadata)
    data = bg_correct(data, bkg, dark)

    if recenter:
        bbox = subimage(data, particle_position, size)
        bbox_corner = np.array([bbox.x.min(), bbox.y.min()])
        found_position = np.round(
            center_find(bbox) + bbox_corner / metadata['spacing'])
        data = subimage(data, found_position, size)
    else:
        data = subimage(data, particle_position, size)
    data = normalize(data)
    if recenter:
        return data, found_position
    return data, None
예제 #12
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)
예제 #13
0
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
import matplotlib.pyplot as plt
import qimage2ndarray as qim

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
# show_sphere_cluster("rainbow", recons)

pic_stack = [abs(recons[i,350:550,450:650]) for i in range(len(recons))]
path = '/home/franz/Desktop/pics/'
import pylab
pylab.gray()
for i, pic in enumerate(pic_stack):
    plt.figure()
예제 #14
0
from holopy.core.io import get_example_data_path, load_average
from holopy.core.process import bg_correct
from scipy.ndimage import measurements
from holopy.scattering import Spheres
from holopy.scattering import calc_holo, Sphere

"""
1)LOAD IMAGE
"""

"""
IMMAGINE DI ESEMPIO, HOLOPY SINGLE SPHERE
"""

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)

"""
IMMAGINE DI ESEMPIO, HOLOPY DOUBLE SPHERES
(simulata e salvata)
"""

#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, )
예제 #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)
예제 #16
0
def fit_multisphere(data_path,
                    a_p,
                    n_p,
                    z_guess,
                    theta_guess,
                    phi_guess,
                    fit_a=False):

    px = cv2.imread(data_path).shape[0]

    data_holo = hp.load_image(data_path,
                              spacing=mag,
                              medium_index=n_m,
                              illum_wavelen=wv,
                              illum_polarization=(1, 0),
                              channel=0)

    data_holo = normalize(data_holo)
    z_p = prior.Uniform(lower_bound=45,
                        upper_bound=100,
                        guess=z_guess,
                        name='z_p')
    theta = prior.Uniform(lower_bound=0,
                          upper_bound=np.pi / 2,
                          guess=theta_guess,
                          name='theta')
    phi = prior.Uniform(lower_bound=0,
                        upper_bound=np.pi,
                        guess=phi_guess,
                        name='phi')
    '''
    #idk why this doesn't work, maybe the fitter has some issue with numpy
    center = (mag*px, mag*px, z_p)
    delta = np.array([np.cos(phi)*np.cos(theta), np.sin(phi)*np.cos(theta), np.sin(theta)])
    c1 =  + 1.001*a_p*delta
    c2 =  - 1.001*a_p*delta
    cluster = np.array([c1, c2])

    s1 = Sphere(center = cluster[0], n = n_p, r = a_p)
    s2 = Sphere(center = cluster[1], n = n_p, r = a_p)
    '''

    if fit_a:
        a_1 = prior.Uniform(lower_bound=a_p * 0.8,
                            upper_bound=a_p * 1.2,
                            guess=a_p,
                            name='a_1')
        a_2 = prior.Uniform(lower_bound=a_p * 0.8,
                            upper_bound=a_p * 1.2,
                            guess=a_p,
                            name='a_2')
    else:
        a_1 = a_p
        a_2 = a_p

    x1 = mag * px / 2 + a_1 * np.cos(phi) * np.cos(theta) * 1.001
    x2 = mag * px / 2 - a_2 * np.cos(phi) * np.cos(theta) * 1.001
    y1 = mag * px / 2 + a_1 * np.cos(theta) * np.sin(phi) * 1.001
    y2 = mag * px / 2 + a_2 * np.cos(theta) * np.sin(phi) * 1.001
    z1 = z_p + a_1 * np.sin(theta) * 1.001
    z2 = z_p - a_2 * np.sin(theta) * 1.001

    s1 = Sphere(center=[x1, y1, z1], n=n_p, r=a_1)
    s2 = Sphere(center=[x2, y2, z2], n=n_p, r=a_2)

    dimer = Spheres([s1, s2], warn=False)

    model = ExactModel(scatterer=dimer,
                       calc_func=calc_holo,
                       noise_sd=None,
                       medium_index=n_m,
                       illum_wavelen=wv,
                       illum_polarization=(1, 0))
    fit_result = hp.fit(data_holo, model)

    return fit_result
예제 #17
0
       - grandezza immagine (standard 1024)
       - directory della immagine raw da analizzare
       - distanze z a cui propagare 
       - directory a cui salvare i grafici e img oggetto
    """

    medium_index = 1.33
    pixel_size = 0.236
    illum_wavelen = 0.6328
    lim = 300
    Lx = 1024
    Ly = 1280
    name = "142"
    cartella = "Poly/2um/1"
    raw_holo = hp.load_image("../Campioni/Flusso/" + cartella +
                             "/img_correct/img_" + name + ".tiff",
                             spacing=pixel_size)
    graph = "../Campioni/Flusso/" + cartella + "/propagation/img_n" + name + ".tiff"
    directory_obj = "../Campioni/Flusso/" + cartella + "/treshold/img_n" + name
    directory_obj_dimension = "../Campioni/Flusso/" + cartella + "/treshold/img_n" + name + "_dimension.tiff"

    z = np.linspace(50, 1000, 100)

    # plot dell'ologramma e calcolo del centro
    plt.figure(0)
    hp.show(raw_holo)
    plt.show()
    plt.clf()

    centro = center_find(raw_holo, centers=1, threshold=0.3, blursize=6.0)
    print(centro)
예제 #18
0
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
예제 #19
0
 def _load_data(self, name):  # need metadata, particle_position!
     data = hp.load_image(name, channel=RGB_CHANNEL, **self.metadata)
     data = bg_correct(data, self._background, self._darkfield)
     data = subimage(data, self.particle_position[::-1], HOLOGRAM_SIZE)
     data = normalize(data)
     return data
예제 #20
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)
예제 #21
0
import holopy as hp
from holopy.scattering import calc_holo, Sphere

sphere = Sphere(n=1.59, r=.5, center=(4, 4, 5))
detector = hp.detector_grid(shape=100, spacing=.1)
medium_index = 1.33
illum_wavelen = 0.660
illum_polarization = (1, 0)

from holopy.core.io import get_example_data_path
imagepath = get_example_data_path('image01.jpg')
exp_img = hp.load_image(imagepath,
                        spacing=0.0851,
                        medium_index=medium_index,
                        illum_wavelen=illum_wavelen,
                        illum_polarization=illum_polarization)
exp_img = exp_img[{'x': slice(0, 100), 'y': slice(0, 100)}]

from holopy.scattering import Spheres
s1 = Sphere(center=(5, 5, 5), n=1.59, r=.5)
s2 = Sphere(center=(4, 4, 5), n=1.59, r=.5)
collection = Spheres([s1, s2])
holo = calc_holo(exp_img, collection)
hp.show(holo)
예제 #22
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)
예제 #23
0
"""

import matplotlib.pyplot as plt
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
from scipy.ndimage import measurements
from holopy.scattering import Spheres
from holopy.scattering import calc_holo, Sphere

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)

z = [17.5, 20, 27]
x = np.linspace(1, 512, 1000)

p1 = np.angle(np.e**(-1j * 2 * np.pi * z[0] / (0.66 / 1.33)))
p2 = np.angle(np.e**(-1j * 2 * np.pi * z[1] / (0.66 / 1.33)))
p3 = np.angle(np.e**(-1j * 2 * np.pi * z[2] / (0.66 / 1.33)))

rec_vol1 = hp.propagate(holo, z[0])
rec_vol2 = hp.propagate(holo, z[1])
예제 #24
0
import holopy as hp
from holopy.scattering import calc_holo, Sphere

sphere = Sphere(n = 1.59, r = .5, center = (4, 4, 5))
detector = hp.detector_grid(shape = 100, spacing = .1)
medium_index = 1.33
illum_wavelen = 0.660
illum_polarization = (1,0)

from holopy.core.io import get_example_data_path
imagepath = get_example_data_path('image01.jpg')
exp_img = hp.load_image(imagepath, spacing=0.0851, medium_index=medium_index, illum_wavelen=illum_wavelen, illum_polarization=illum_polarization)
exp_img = exp_img[{'x':slice(0,100),'y':slice(0,100)}]

from holopy.scattering import Spheres
s1 = Sphere(center=(5, 5, 5), n = 1.59, r = .5)
s2 = Sphere(center=(4, 4, 5), n = 1.59, r = .5)
collection = Spheres([s1, s2])
holo = calc_holo(exp_img, collection)
hp.show(holo)