Professional Documents
Culture Documents
3D Scan Slice Reconstructions
3D Scan Slice Reconstructions
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.
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.
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.
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, x1), min(len(image), x+2)):
for j in range(max(0, y1), min(len(image[0]), y+2)):
if not (x == i and y == j):
if image[i][j] == neighbour_type:
return True
return False