You are on page 1of 3

Description

Modified scan generation algorithm:


• User declares final coordinates (final_coords ) to which tomography scan should be
transformed and accuracy, which will decide what can be error between searched
coordinates and found coordinates.
• User provides original scan data, which consists of slices and actual coordinates of slices.
• For each coordinate in final_coords there is run binary search of slice (see later for detailed
description), where "between image" is generated using image interpolation algorithm
described below. The generated slice is placed in new set of slices. As algorithm produces
intermediate images as it approaches “requested” slice those intermediate slices are also
“cached” in case they are to be reused in later algorithm runs.
• When new set of slices is full, new 3D scan is created with generated slices and requested
coordinates and it is returned to user.

Algorithm, to work, needs two nearest slices of requested, one above, one below, coordinates of
these, requested slice coordinates and accuracy. After finding these _binary_search algorithm is run
and return generated between image for requested coordinates.

Binary search/reconstruction of slices


Pseudo code. The example code below use Image interpolation algorithm described below
(get_between_image function).
    def _binary_search(first_image, second_image, first_coords, second_coords, searched_coords, accuracy):
# get_between_image either interpolates images or retrieves one from cache if already computed
        between_image = get_between_image(first_image, second_image)
        between_coords = (first_coords + second_coords)/2.0
# between_image is to be cached here (along with it's coordinate (between_coords)

        if abs(between_coords ­ searched_coords) <= accuracy:
            return Slice(between_image)
        elif searched_coords < between_coords:
            return _binary_search(
                first_image, between_image, first_coords, between_coords, searched_coords, accuracy
            )
        else:
            return _binary_search(
                between_image, second_image, between_coords, second_coords, searched_coords, accuracy
            )

Embodiment

fig 1.

Imagine a simple case where we have scan with only two scans: one at coordinate 0 and second at
1. User needs to have slice at 0.77, we assume accuracy of 0.05 is enough.
On first iteration algorithm will generate “between_image” at coordinate 0.5, and decide to continue
(with slice at 0.5 and slice at 1).
On second iteration algorithm will generate “between_image” at coordinate 0.75 (midpoint 0.5-1),
and decide this is what was requested as distance from 0.77 (requested) is < 0.05 (accuracy) –
image at 0.75 is returned.

Image interpolation algorithm - description


The interpolation algorithm used in the implementation of described invention is cellular automaton
with rules which simulate very dense fluid.
Color areas (white and black in example code below) of both images generates dense fluids, which
are flooding free spaces until they cannot flow any further.
Dense fluid is connected with area which generated it and while algorithm stops, fluid gives the
area color to the place where it flooded.

Prerequisites of algorithm
• both images should have the same width and height
• both images which are products to produce between image should be converted to black-
white image or to image with color palette with very few colors.

We start with interpolated image filled with white. Then we look at both source slices and set pixels
(voxels actually) of interpolated image to black at coordinates where there is black on BOTH source
slices, and leave white where there is white on BOTH source slices. For coordinates where source
slices differ we set interpolated pixels to “undecided” (and yes, remember that there are some
undecided pixels to process later).
After this step we have interpolated image with black, white and undecided pixels.
Then we go through pixels in interpolated image and for “undecided” set them either as growing or
shrinking with the following rules:
• if pixel was white on first slice and now has any black neighbor it is set as “growing”
• if pixel was white on first slice and now has any white neighbor it is set as “shrinking”
• if pixel was black on first slice and now has any black neighbor it is set as “growing”
• if pixel was black on first slice and now has any white neighbor it is set as “shrinking”
After this step we have interpolated image with black, white, growing and shrinking pixels.
Then we go through pixels in interpolated image again and replace growing pixels with black and
shrinking with white. This completes interpolation and image is returned.

Pseudo code (for 1 bit (black and white) input images):


    def get_between_image(first_image, second_image, width, height):
        between_image = generate_empty_image(width, height, with_color=WHITE_COLOR)

        for i in range(0, width):
            for j in range(0, height):
                if first_image[i][j] == BLACK_PIXEL and second_image[i][j] == BLACK_PIXEL:
                    between_image[i][j] = BLACK_PIXEL
                elif first_image[i][j] != second_image[i][j]:
                    between_image[i][j] = UNDECIDED_PIXEL
   at_least_one_undecided_exists = True

        while at_least_one_undecided_exists:
            at_least_one_undecided_exists = False
            undecided_no = 0
            for i in range(0, width):
                for j in range(0, height):
                    if between_image[i][j] == UNDECIDED_PIXEL:
                        at_least_one_undecided_exists = True
                        undecided_no +=1
                        if first_image[i][j] == WHITE_PIXEL and has_neighbour(between_image, i, j, BLACK_PIXEL):
                            between_image[i][j] = GROWING_PIXEL
                        elif first_image[i][j] == WHITE_PIXEL and has_neighbour(between_image, i, j, WHITE_PIXEL):
                            between_image[i][j] = SHRINKING_PIXEL
                        elif first_image[i][j] == BLACK_PIXEL and has_neighbour(between_image, i, j, WHITE_PIXEL):
                            between_image[i][j] = SHRINKING_PIXEL
                        elif first_image[i][j] == BLACK_PIXEL and has_neighbour(between_image, i, j, BLACK_PIXEL):
                            between_image[i][j] = GROWING_PIXEL
            for i in range(0, width):
                for j in range(0, height):
                    if between_image[i][j] == GROWING_PIXEL:
                        between_image[i][j] = BLACK_PIXEL
                    elif between_image[i][j] == SHRINKING_PIXEL:
                        between_image[i][j] = WHITE_PIXEL
        return between_image

    def has_neighbour(image, x, y, neighbour_type):
        for i in range(max(0, x­1), min(len(image), x+2)):
            for j in range(max(0, y­1), min(len(image[0]), y+2)):
                if not (x == i and y == j):
                    if image[i][j] == neighbour_type:
                        return True
        return False

You might also like