Exemplo n.º 1
0
    def get_mask_factories(self):
        if self.dataset.shape.sig.dims != 2:
            raise ValueError("can only handle 2D signals currently")

        (detector_y, detector_x) = self.dataset.shape.sig

        cx = self.parameters['cx']
        cy = self.parameters['cy']
        r = self.parameters['r']
        dtype = self.dtype

        def disk_mask():
            return masks.circular(
                centerX=cx, centerY=cy,
                imageSizeX=detector_x,
                imageSizeY=detector_y,
                radius=r,
            )

        return [
            disk_mask,
            lambda: masks.gradient_x(
                imageSizeX=detector_x,
                imageSizeY=detector_y,
                dtype=dtype,
            ) * disk_mask(),
            lambda: masks.gradient_y(
                imageSizeX=detector_x,
                imageSizeY=detector_y,
                dtype=dtype,
            ) * disk_mask(),
        ]
Exemplo n.º 2
0
Arquivo: com.py Projeto: sk1p/LiberTEM
def com_masks_generic(detector_y, detector_x, base_mask_factory):
    """
    Create a CoM mask stack with a generic selection mask factory

    Parameters
    ----------
    detector_y : int
        The detector height
    detector_x : int
        The detector width
    base_mask_factory : () -> np.array
        A factory function for creating the selection mask

    Returns
    -------
    List[Function]
        The mask stack as a list of factory functions
    """
    return [
        base_mask_factory,
        lambda: masks.gradient_y(
            imageSizeX=detector_x,
            imageSizeY=detector_y,
        ) * base_mask_factory(),
        lambda: masks.gradient_x(
            imageSizeX=detector_x,
            imageSizeY=detector_y,
        ) * base_mask_factory(),
    ]
Exemplo n.º 3
0
    def get_mask_factories(self):
        cx = self.parameters['cx']
        cy = self.parameters['cy']
        r = self.parameters['r']
        frame_size = self.dataset.shape[2:]

        def disk_mask():
            return masks.circular(
                centerX=cx,
                centerY=cy,
                imageSizeX=frame_size[1],
                imageSizeY=frame_size[0],
                radius=r,
            )

        return [
            disk_mask,
            lambda: masks.gradient_x(
                imageSizeX=frame_size[1],
                imageSizeY=frame_size[0],
                dtype=self.dtype,
            ) * (np.ones(frame_size) * disk_mask()),
            lambda: masks.gradient_y(
                imageSizeX=frame_size[1],
                imageSizeY=frame_size[0],
                dtype=self.dtype,
            ) * (np.ones(frame_size) * disk_mask()),
        ]
Exemplo n.º 4
0
def do_com(fn, tileshape):
    ds = H5DataSet(
        path=fn,
        ds_path="data",
        tileshape=tileshape,
        target_size=512*1024*1024,
    )

    masks = [
        # summation of all pixels:
        lambda: np.ones(shape=ds.shape[2:]),

        # gradient from left to right
        lambda: gradient_x(*ds.shape[2:]),

        # gradient from top to bottom
        lambda: gradient_y(*ds.shape[2:]),
    ]
    job = ApplyMasksJob(dataset=ds, mask_factories=masks)
    print(job.masks.computed_masks)
    print("\n\n")
    executor = InlineJobExecutor()
    full_result = np.zeros(shape=(3,) + ds.shape[:2])
    color = np.zeros(shape=(3,) + ds.shape[:2])
    for result in executor.run_job(job):
        for tile in result:
            print(tile)
            print(tile.data[0])
            color[tile.tile_slice.get()[:2]] += 1
            tile.copy_to_result(full_result)
    x_centers = np.divide(full_result[1], full_result[0])
    y_centers = np.divide(full_result[2], full_result[0])
    print(color)

    return full_result, x_centers, y_centers
Exemplo n.º 5
0
def com_masks_factory(detector_y, detector_x, cy, cx, r):
    def disk_mask():
        return masks.circular(
            centerX=cx, centerY=cy,
            imageSizeX=detector_x,
            imageSizeY=detector_y,
            radius=r,
        )

    return [
        disk_mask,
        lambda: masks.gradient_y(
            imageSizeX=detector_x,
            imageSizeY=detector_y,
        ) * disk_mask(),
        lambda: masks.gradient_x(
            imageSizeX=detector_x,
            imageSizeY=detector_y,
        ) * disk_mask(),
    ]
Exemplo n.º 6
0
 def _make_com(cx, cy, r, shape):
     disk_mask = masks.circular(
         centerX=cx,
         centerY=cy,
         imageSizeX=frame_size[1],
         imageSizeY=frame_size[0],
         radius=r,
     )
     return [
         lambda: disk_mask,
         lambda: masks.gradient_x(
             imageSizeX=frame_size[1],
             imageSizeY=frame_size[0],
             dtype=dtype,
         ) * (np.ones(frame_size) * disk_mask),
         lambda: masks.gradient_y(
             imageSizeX=frame_size[1],
             imageSizeY=frame_size[0],
             dtype=dtype,
         ) * (np.ones(frame_size) * disk_mask),
     ]