Update app.py
Browse files
app.py
CHANGED
|
@@ -368,6 +368,9 @@ class DicomAnalyzer:
|
|
| 368 |
"""
|
| 369 |
Creates an Excel file with results in a formatted table,
|
| 370 |
adding SNR/CNR formulas and averaging blocks for StdDev and CNR.
|
|
|
|
|
|
|
|
|
|
| 371 |
"""
|
| 372 |
try:
|
| 373 |
if not self.results:
|
|
@@ -491,18 +494,16 @@ class DicomAnalyzer:
|
|
| 491 |
cnr_header.alignment = center_alignment
|
| 492 |
current_row += 1
|
| 493 |
|
| 494 |
-
# ุญุณุงุจ ู
ุชูุณุท CNR ููุตู ุงูุซุงูู ูู ูู pair
|
| 495 |
for i, size in enumerate(phantom_sizes):
|
| 496 |
-
# ุงูุตู ุงูุซุงูู ูู row_pairs[i][1]
|
| 497 |
row_number = row_pairs[i][1]
|
| 498 |
cnr_cells = []
|
| 499 |
-
|
| 500 |
-
# ูุฌู
ุน ูู ุงูุฎูุงูุง ุงูุชู ูููุง ุงูุตูุบุฉ CNR (ููู ุงูุนู
ูุฏ ุจุนุฏ ุขุฎุฑ ุนู
ูุฏ ูู ุงูู
ุฌู
ูุนุฉ)
|
| 501 |
for cols in column_groups:
|
| 502 |
formula_col = get_column_letter(column_index_from_string(cols[-1]) + 1)
|
| 503 |
cnr_cell_ref = f"{formula_col}{row_number}"
|
| 504 |
|
| 505 |
-
#
|
| 506 |
mean_col = cols[1]
|
| 507 |
std_col = cols[2]
|
| 508 |
|
|
@@ -517,7 +518,7 @@ class DicomAnalyzer:
|
|
| 517 |
except:
|
| 518 |
mean1_val, mean2_val, std2_val = 0, 0, 0
|
| 519 |
|
| 520 |
-
# ูู ูููุง ุตูุฑ => ูุง ูุถูู
|
| 521 |
if not (mean1_val == 0 and mean2_val == 0 and std2_val == 0):
|
| 522 |
cnr_cells.append(cnr_cell_ref)
|
| 523 |
|
|
@@ -525,12 +526,11 @@ class DicomAnalyzer:
|
|
| 525 |
size_cell.alignment = center_alignment
|
| 526 |
|
| 527 |
if cnr_cells:
|
| 528 |
-
# ูุจูู ุตูุบุฉ
|
| 529 |
-
|
| 530 |
-
cnr_formula = f'=IFERROR(AVERAGEIF({cnr_range}, "<>0"), "")'
|
| 531 |
|
| 532 |
avg_cell = ws.cell(row=current_row, column=2)
|
| 533 |
-
avg_cell.value =
|
| 534 |
avg_cell.number_format = '0.000'
|
| 535 |
avg_cell.alignment = center_alignment
|
| 536 |
|
|
@@ -599,6 +599,21 @@ class DicomAnalyzer:
|
|
| 599 |
})
|
| 600 |
return image, self.format_results()
|
| 601 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 602 |
def undo_last(self, image):
|
| 603 |
if self.results:
|
| 604 |
self.results.pop()
|
|
@@ -641,6 +656,7 @@ def create_interface():
|
|
| 641 |
with gr.Row():
|
| 642 |
blank_btn = gr.Button("Add Blank Row")
|
| 643 |
zero_btn = gr.Button("Add Zero Row")
|
|
|
|
| 644 |
undo_btn = gr.Button("Undo Last")
|
| 645 |
save_btn = gr.Button("Save Results")
|
| 646 |
save_formatted_btn = gr.Button("Save Formatted Results")
|
|
@@ -730,7 +746,14 @@ def create_interface():
|
|
| 730 |
inputs=image_display,
|
| 731 |
outputs=[image_display, results_display]
|
| 732 |
)
|
| 733 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 734 |
undo_btn.click(
|
| 735 |
fn=analyzer.undo_last,
|
| 736 |
inputs=image_display,
|
|
|
|
| 368 |
"""
|
| 369 |
Creates an Excel file with results in a formatted table,
|
| 370 |
adding SNR/CNR formulas and averaging blocks for StdDev and CNR.
|
| 371 |
+
|
| 372 |
+
NOTE: CNR Averages uses AVERAGE() and we skip any cell references where
|
| 373 |
+
Mean1, Mean2, StdDev2 are all zero. So we avoid AVERAGEIF complexities.
|
| 374 |
"""
|
| 375 |
try:
|
| 376 |
if not self.results:
|
|
|
|
| 494 |
cnr_header.alignment = center_alignment
|
| 495 |
current_row += 1
|
| 496 |
|
| 497 |
+
# ุญุณุงุจ ู
ุชูุณุท CNR ููุตู ุงูุซุงูู ูู ูู pair ุจุงุณุชุฎุฏุงู
AVERAGE ููุท
|
| 498 |
for i, size in enumerate(phantom_sizes):
|
|
|
|
| 499 |
row_number = row_pairs[i][1]
|
| 500 |
cnr_cells = []
|
| 501 |
+
|
|
|
|
| 502 |
for cols in column_groups:
|
| 503 |
formula_col = get_column_letter(column_index_from_string(cols[-1]) + 1)
|
| 504 |
cnr_cell_ref = f"{formula_col}{row_number}"
|
| 505 |
|
| 506 |
+
# ููุฑุฃ Mean1,Mean2,Std2 ููุชุญูู
|
| 507 |
mean_col = cols[1]
|
| 508 |
std_col = cols[2]
|
| 509 |
|
|
|
|
| 518 |
except:
|
| 519 |
mean1_val, mean2_val, std2_val = 0, 0, 0
|
| 520 |
|
| 521 |
+
# ูู ูููุง ุตูุฑ => ูุง ูุถูู ุงูุฎููุฉ
|
| 522 |
if not (mean1_val == 0 and mean2_val == 0 and std2_val == 0):
|
| 523 |
cnr_cells.append(cnr_cell_ref)
|
| 524 |
|
|
|
|
| 526 |
size_cell.alignment = center_alignment
|
| 527 |
|
| 528 |
if cnr_cells:
|
| 529 |
+
# ูุจูู ุตูุบุฉ Excel: =IFERROR(AVERAGE(G3,M3,...),"")
|
| 530 |
+
average_formula = f'=IFERROR(AVERAGE({",".join(cnr_cells)}), "")'
|
|
|
|
| 531 |
|
| 532 |
avg_cell = ws.cell(row=current_row, column=2)
|
| 533 |
+
avg_cell.value = average_formula
|
| 534 |
avg_cell.number_format = '0.000'
|
| 535 |
avg_cell.alignment = center_alignment
|
| 536 |
|
|
|
|
| 599 |
})
|
| 600 |
return image, self.format_results()
|
| 601 |
|
| 602 |
+
def add_two_zero_rows(self, image):
|
| 603 |
+
"""
|
| 604 |
+
Adds two consecutive rows of zeros.
|
| 605 |
+
"""
|
| 606 |
+
for _ in range(2):
|
| 607 |
+
self.results.append({
|
| 608 |
+
'Area (mmยฒ)': '0.000',
|
| 609 |
+
'Mean': '0.000',
|
| 610 |
+
'StdDev': '0.000',
|
| 611 |
+
'Min': '0.000',
|
| 612 |
+
'Max': '0.000',
|
| 613 |
+
'Point': '(0, 0)'
|
| 614 |
+
})
|
| 615 |
+
return image, self.format_results()
|
| 616 |
+
|
| 617 |
def undo_last(self, image):
|
| 618 |
if self.results:
|
| 619 |
self.results.pop()
|
|
|
|
| 656 |
with gr.Row():
|
| 657 |
blank_btn = gr.Button("Add Blank Row")
|
| 658 |
zero_btn = gr.Button("Add Zero Row")
|
| 659 |
+
zero2_btn = gr.Button("Add Two Zero Rows") # <-- New button
|
| 660 |
undo_btn = gr.Button("Undo Last")
|
| 661 |
save_btn = gr.Button("Save Results")
|
| 662 |
save_formatted_btn = gr.Button("Save Formatted Results")
|
|
|
|
| 746 |
inputs=image_display,
|
| 747 |
outputs=[image_display, results_display]
|
| 748 |
)
|
| 749 |
+
|
| 750 |
+
# ุฒุฑ ุฅุถุงูุฉ ุตููู ุตูุฑ
|
| 751 |
+
zero2_btn.click(
|
| 752 |
+
fn=analyzer.add_two_zero_rows,
|
| 753 |
+
inputs=image_display,
|
| 754 |
+
outputs=[image_display, results_display]
|
| 755 |
+
)
|
| 756 |
+
|
| 757 |
undo_btn.click(
|
| 758 |
fn=analyzer.undo_last,
|
| 759 |
inputs=image_display,
|