Skip to content

Commit

Permalink
Merge branch 'develop' into attest
Browse files Browse the repository at this point in the history
  • Loading branch information
andylassiter committed Aug 2, 2024
2 parents 9edc9b6 + bc32d34 commit 4d0281e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
FROM python:3.11-slim

# Update the package list and upgrade installed packages
RUN apt-get update && \
apt-get upgrade -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Update pip and setuptools to the latest version
RUN pip install --no-cache-dir --upgrade pip setuptools

# Create a non-root user and group
RUN addgroup --system appgroup && adduser --system --ingroup appgroup appuser

Expand Down
4 changes: 3 additions & 1 deletion splitter_of_mice/splitter_of_mice/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ def error(self, message):
sys.exit(SoM(a.file_path, modality=a.mod, dicom=a.dicom).split_mice(a.out_dir, save_analyze=a.a,
num_anim=a.n, sep_thresh=a.t, margin=a.m,
minpix=a.p, output_qc=a.q, suffix_map=a.sm,
zip=a.z, remove_bed=a.remove_bed))
zip=a.z, remove_bed=a.remove_bed,
pet_img_size=a.pet_img_size,
ct_img_size=a.ct_img_size))
3 changes: 3 additions & 0 deletions splitter_of_mice/splitter_of_mice/rectangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def ht(self):
def ctr(self):
return self.xlt + self.wid() * .5, self.ylt + self.ht() * .5

def area(self):
return self.wid() * self.ht()

def expand(self, m):
self.xlt -= m[0]
self.xrb += m[0]
Expand Down
42 changes: 41 additions & 1 deletion splitter_of_mice/splitter_of_mice/splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def add_cuts_to_image(im, boxes, desc_map, save_analyze_dir=None, dicom_metadata
# _,data=im.submemmap(ix=ix,data=im.img_data[:,ymin:ymax,xmin:xmax,:])
# print(data.shape)

metadata = dicom_metadata[desc] if desc in dicom_metadata else None
metadata = dicom_metadata[desc] if (dicom_metadata and desc in dicom_metadata) else None
new_img = SubImage(parent_image=im, img_data=data, filename=fname + '.img',
cut_coords=[(xmin, xmax), (ymin, ymax)], desc=desc, metadata=metadata)

Expand Down Expand Up @@ -200,6 +200,8 @@ def get_valid_regs(label):
logger.debug('bboxes' + str([p.bbox for p in props]))
valid_reg = [p for p in props if p.area >= min_pts]
logger.info('valid regions detected: ' + str(len(valid_reg)))
logger.info('{ctr,area}:' + str([(p.centroid, p.area) for p in valid_reg]))

return valid_reg

@staticmethod
Expand Down Expand Up @@ -271,6 +273,42 @@ def split_coords(img, valid_reg):
lr = [{'desc': big_box.quadrant(r.ctr()), 'rect': r} for r in rs]
SoM.harmonize_rects(lr)
out_boxes = lr

else:
logger.error(f"Too many regions detected: {len(valid_reg)}. "
f"Attempting to merge regions within the same quadrant.")

rs = [Rect(bb=valid_reg[i].bbox, label=valid_reg[i].label) for i in range(len(valid_reg))]
big_box = Rect.union_list(rs)
lr = [{'desc': big_box.quadrant(r.ctr()), 'rect': r} for r in rs]
merged: list[dict] = []
for r in lr:
if r['desc'] in [m['desc'] for m in merged]:
# if the quadrant already exists in merged, union the rects
for m in merged:
if m['desc'] == r['desc']:
m['rect'] = m['rect'].union(r['rect'])
else:
# if the quadrant does not exist in merged, add it
merged.append(r)

# update rect labels
for i, r in enumerate(merged):
if r['desc'] == 'lt':
r['rect'].label = 1
elif r['desc'] == 'rt':
r['rect'].label = 2
elif r['desc'] == 'lb':
r['rect'].label = 3
elif r['desc'] == 'rb':
r['rect'].label = 4

SoM.harmonize_rects(merged)
out_boxes = merged

for box in out_boxes:
logger.info(f"Box: {box['desc']}, Area: {box['rect'].area()}, Center: {box['rect'].ctr()}")

return out_boxes

@staticmethod
Expand Down Expand Up @@ -500,8 +538,10 @@ def split_mice_ct(self, outdir, desc_map, save_analyze=False, num_anim=None,
# adjust the size of the cuts if img_size is specified.
# helpful for keeping the same image size across multiple scans.
if img_size is not None:
logger.info(f"Adjusting cuts to size: {img_size}")
for cut in cuts:
cut['rect'].adjust_to_size(img_size)
logger.info(f"Cut: {cut['desc']}, Area: {cut['rect'].area()}, Center: {cut['rect'].ctr()}")

save_analyze_dir = outdir if save_analyze else None
# save_analyze_dir=None #debug
Expand Down

0 comments on commit 4d0281e

Please sign in to comment.