Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
ENH: Butterfly device support - arbitrary video frame size (#123)
Browse files Browse the repository at this point in the history
ENH: v2.0.1 supports broader range of butterfly video frame sizes
  • Loading branch information
aylward authored Jan 25, 2023
1 parent c97d7ef commit 0659d34
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 23 deletions.
7 changes: 6 additions & 1 deletion ARGUS/ARGUS_onsd_roi_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def inference(self, ar_image, ar_labels):
while max_l[method] in indxs:
max_l[method] += 1

num_width = 0
stddev_width = 0
for slice_num in range(min_l[method],max_l[method]):
top=0
while np.count_nonzero(ar_labels[slice_num,:,top] == 2) < min_nerve_size / 2 and top<image_size[1]-10:
Expand All @@ -85,9 +87,12 @@ def inference(self, ar_image, ar_labels):
width.sort(reverse=True)
slice_width = width[int(len(width)*0.02)]
max_width = max(max_width, slice_width)
stddev_width += np.std(width)
num_width += 1

stddev_width /= num_width
classification = 0
if max_width > self.decision_distance:
classification = 1

return classification, max_width, min_l, max_l
return classification, [max_width, stddev_width], min_l, max_l
59 changes: 47 additions & 12 deletions ARGUS/ARGUS_preprocess_butterfly.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,22 @@ def get_ruler_points(self, img):
""" Find points along ruler on right side of image """
y_min = 40
y_max = 1080
min_x = 907
max_x = 908

max_x = img.shape[2]-1
count = np.count_nonzero(img[0,y_min:y_max,max_x]//100)
while max_x > img.shape[2]-20 and count <= 12:
max_x -= 1
count = np.count_nonzero(img[0,y_min:y_max,max_x]//100)
min_x = max_x - 1
count = np.count_nonzero(img[0,y_min:y_max,min_x]//100)
while min_x > img.shape[2]-25 and count >= 10:
min_x -= 1
count = np.count_nonzero(img[0,y_min:y_max,min_x]//100)
mid_x = (max_x * 3 + min_x) // 4
min_x = mid_x-1
max_x = mid_x+1
#min_x = img.shape[2] - 4 #907
#max_x = img.shape[2] - 5 #908
mid = np.mean((img[0,y_min:y_max,min_x:max_x]//100),axis=1)
y = np.flatnonzero(mid)+y_min
return y
Expand Down Expand Up @@ -50,26 +64,47 @@ def get_roi(self, img):

tic_num = len(yCenters)
tic_min = yCenters[0]
tic_max = yCenters[len(yCenters)-1]
tic_max = yCenters[-1]
tic_diff = avg
return tic_num,tic_min,tic_max,tic_diff
return tic_num,int(tic_min),int(tic_max),tic_diff

def process(self, vid, new_size):

tic_num,tic_min,tic_max,tic_diff = self.get_roi(vid)
vid_array = itk.GetArrayFromImage(vid)
tic_num,tic_min,tic_max,tic_diff = self.get_roi(vid_array)

pixel_spacing = 2/tic_diff
spacing = [pixel_spacing,pixel_spacing,vid.GetSpacing()[2]]
vid.SetSpacing(spacing)

center_x = int((780-120)/2+120)
offset_x = center_x-120
crop_min_x = 120
crop_max_x = 780
crop_min_y = int(tic_min+tic_diff)
crop_max_y = int(tic_max-tic_diff)
crop_min_z = 0
crop_max_z = vid.shape[0]

crop_min_y = int(tic_min+tic_diff)
crop_max_y = int(tic_max-tic_diff)

mid_x = vid_array.shape[2]//2
min_x = mid_x-10
count = np.count_nonzero(vid_array[0,crop_min_y:crop_max_y,min_x]//50)
while min_x > 100 and count > 100:
min_x -= 1
count = np.count_nonzero(vid_array[0,crop_min_y:crop_max_y,min_x]//50)
max_x = mid_x + 1
count = np.count_nonzero(vid_array[0,crop_min_y:crop_max_y,max_x]//50)
while max_x < vid_array.shape[2]-100 and count > 100:
max_x += 1
count = np.count_nonzero(vid_array[0,crop_min_y:crop_max_y,max_x]//50)
crop_min_x = min_x + 10
crop_max_x = max_x - 10
#if vid_array.shape[2] < 1000:
#crop_min_x = 120
#crop_max_x = 780
#else:
#crop_min_x = 480
#crop_max_x = 1180
#center_x = int((crop_max_x-crop_min_x)/2+crop_min_x)
#offset_x = center_x-crop_min_x

Crop = tube.CropImage.New(vid)
Crop.SetMin([crop_min_x,crop_min_y,crop_min_z])
Crop.SetMax([crop_max_x,crop_max_y,crop_max_z])
Expand All @@ -91,4 +126,4 @@ def process(self, vid, new_size):
Resample.Update()
img = Resample.GetOutput()

return img
return img
2 changes: 1 addition & 1 deletion ARGUS/Deployment/installer.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

[Setup]
AppVersion=2.0.beta02
AppVersion=2.0.1
AppName=ARGUS
AppContact=Kitware, Inc.
AppPublisher=Kitware, Inc.
Expand Down
27 changes: 18 additions & 9 deletions PNB/ARGUS_pnb_workflow_experiment.ipynb

Large diffs are not rendered by default.

0 comments on commit 0659d34

Please sign in to comment.