Skip to content

Commit

Permalink
Remove references to volumestore.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjanusz committed Jan 27, 2019
1 parent ed5541a commit f8d97fb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
12 changes: 6 additions & 6 deletions ffn/inference/resegmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,24 @@ def get_canvas(point, radius, runner):
end = subvol_size + corner

if (np.any(corner < 0) or
runner.init_seg_volstore.size.z <= end[0] or
runner.init_seg_volstore.size.y <= end[1] or
runner.init_seg_volstore.size.x <= end[2]):
runner.init_seg_volume.shape[1] <= end[0] or
runner.init_seg_volume.shape[2] <= end[1] or
runner.init_seg_volume.shape[3] <= end[2]):
logging.error('Not enough context for: %d, %d, %d; corner: %r; end: %r',
point[2], point[1], point[0], corner, end)
return None, None

return runner.make_canvas(corner, subvol_size, keep_history=True)


def process_point(request, runner, point_num):
def process_point(request, runner, point_num, voxel_size):
"""Runs resegmentation for a specific point.
Args:
request: ResegmentationRequest proto
runner: inference Runner object
point_num: index of the point of interest within the proto
voxel_size: (z, y, x) voxel size in physical units
"""
with timer_counter(runner.counters, 'resegmentation'):
target_path = get_target_path(request, point_num)
Expand Down Expand Up @@ -208,8 +209,7 @@ def unalign_prob(prob):
logging.info('processing object %d', i)

with timer_counter(canvas.counters, 'edt'):
ps = runner.init_seg_volstore.info.pixelsize
dists = ndimage.distance_transform_edt(seg, sampling=(ps.z, ps.y, ps.x))
dists = ndimage.distance_transform_edt(seg, sampling=voxel_size)
# Do not seed where not enough context is available.
dists[:canvas.margin[0], :, :] = 0
dists[:, :canvas.margin[1], :] = 0
Expand Down
33 changes: 16 additions & 17 deletions ffn/inference/resegmentation_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ def parse_resegmentation_filename(filename):
return id1, id2, x, y, z


def evaluate_endpoint_resegmentation(filename, seg_volstore,
def evaluate_endpoint_resegmentation(filename, seg_volume,
resegmentation_radius,
threshold=0.5):
"""Evaluates endpoint resegmentation.
Args:
filename: path to the file containing resegmentation results
seg_volstore: VolumeStore object with the original segmentation
seg_volume: volume object with the original segmentation
resegmentation_radius: (z, y, x) radius of the resegmentation subvolume
threshold: threshold at which to create objects from the predicted
object map
Expand Down Expand Up @@ -130,10 +130,10 @@ def evaluate_endpoint_resegmentation(filename, seg_volstore,
prob = np.nan_to_num(prob) # nans indicate unvisited voxels

sr = result.segmentation_radius
orig_seg = seg_volstore[0,
(z - sr.z):(z + sr.z + 1),
(y - sr.y):(y + sr.y + 1),
(x - sr.x):(x + sr.x + 1)][0, ...]
orig_seg = seg_volume[0,
(z - sr.z):(z + sr.z + 1),
(y - sr.y):(y + sr.y + 1),
(x - sr.x):(x + sr.x + 1)][0, ...]
seg1 = orig_seg == id1
if not np.any(seg1):
raise InvalidBaseSegmentatonError()
Expand All @@ -157,18 +157,20 @@ def evaluate_endpoint_resegmentation(filename, seg_volstore,
return result


def evaluate_pair_resegmentation(filename, seg_volstore,
def evaluate_pair_resegmentation(filename, seg_volume,
resegmentation_radius,
analysis_radius,
voxel_size,
threshold=0.5):
"""Evaluates segment pair resegmentation.
Args:
filename: path to the file containing resegmentation results
seg_volstore: VolumeStore object with the original segmentation
seg_volume: VolumeStore object with the original segmentation
resegmentation_radius: (z, y, x) radius of the resegmentation subvolume
analysis_radius: (z, y, x) radius of the subvolume in which to perform
analysis
voxel_size: (z, y, x) voxel size in physical units
threshold: threshold at which to create objects from the predicted
object map
Expand Down Expand Up @@ -221,10 +223,10 @@ def evaluate_pair_resegmentation(filename, seg_volstore,
r = result.eval.radius
r.z, r.y, r.x = analysis_r

seg = seg_volstore[0,
(z - analysis_r[0]):(z + analysis_r[0] + 1),
(y - analysis_r[1]):(y + analysis_r[1] + 1),
(x - analysis_r[2]):(x + analysis_r[2] + 1)][0, ...]
seg = seg_volume[0,
(z - analysis_r[0]):(z + analysis_r[0] + 1),
(y - analysis_r[1]):(y + analysis_r[1] + 1),
(x - analysis_r[2]):(x + analysis_r[2] + 1)][0, ...]
seg1 = seg == id1
seg2 = seg == id2
result.eval.num_voxels_a = int(np.sum(seg1))
Expand All @@ -234,13 +236,10 @@ def evaluate_pair_resegmentation(filename, seg_volstore,
raise InvalidBaseSegmentatonError()

# Record information about the size of the original segments.
sampling = (seg_volstore.info.pixelsize.z,
seg_volstore.info.pixelsize.y,
seg_volstore.info.pixelsize.x)
result.eval.max_edt_a = float(
ndimage.distance_transform_edt(seg1, sampling=sampling).max())
ndimage.distance_transform_edt(seg1, sampling=voxel_size).max())
result.eval.max_edt_b = float(
ndimage.distance_transform_edt(seg2, sampling=sampling).max())
ndimage.distance_transform_edt(seg2, sampling=voxel_size).max())

# Offset of the analysis subvolume within the resegmentation subvolume.
delta = np.array(resegmentation_radius) - analysis_r
Expand Down

0 comments on commit f8d97fb

Please sign in to comment.