HeshamAI commited on
Commit
6492534
·
verified ·
1 Parent(s): df49e9f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -3
app.py CHANGED
@@ -133,7 +133,6 @@ class DicomAnalyzer:
133
  except Exception as e:
134
  print(f"Error loading DICOM file: {str(e)}")
135
  return None, f"Error loading DICOM file: {str(e)}"
136
-
137
  def normalize_image(self, image):
138
  try:
139
  normalized = cv2.normalize(
@@ -187,6 +186,7 @@ class DicomAnalyzer:
187
  except Exception as e:
188
  print(f"Error handling keyboard input: {str(e)}")
189
  return self.display_image
 
190
  def update_display(self):
191
  try:
192
  if self.original_display is None:
@@ -319,6 +319,35 @@ class DicomAnalyzer:
319
  except Exception as e:
320
  print(f"Error analyzing ROI: {str(e)}")
321
  return self.display_image, f"Error analyzing ROI: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
  def save_formatted_results(self, output_path):
323
  try:
324
  if not self.results:
@@ -396,7 +425,6 @@ class DicomAnalyzer:
396
  cell = ws[f"{col}{row}"]
397
  if cell.value is not None:
398
  cell.alignment = center_alignment
399
-
400
  # StdDev Averages
401
  current_row = 32
402
  stddev_header = ws.cell(row=current_row, column=1, value="StdDev Averages")
@@ -753,4 +781,4 @@ if __name__ == "__main__":
753
  print(f"Error launching application: {str(e)}")
754
  logger.error(f"Error launching application: {str(e)}")
755
  logger.error(traceback.format_exc())
756
- raise e
 
133
  except Exception as e:
134
  print(f"Error loading DICOM file: {str(e)}")
135
  return None, f"Error loading DICOM file: {str(e)}"
 
136
  def normalize_image(self, image):
137
  try:
138
  normalized = cv2.normalize(
 
186
  except Exception as e:
187
  print(f"Error handling keyboard input: {str(e)}")
188
  return self.display_image
189
+
190
  def update_display(self):
191
  try:
192
  if self.original_display is None:
 
319
  except Exception as e:
320
  print(f"Error analyzing ROI: {str(e)}")
321
  return self.display_image, f"Error analyzing ROI: {str(e)}"
322
+ def add_formulas_to_template(self, ws, row_pair, col_group, red_font):
323
+ """
324
+ Inserts SNR (first row) and CNR (second row) formulas with IFERROR.
325
+ """
326
+ try:
327
+ base_col = col_group[1] # Mean column
328
+ std_col = col_group[2] # StdDev column
329
+
330
+ row1, row2 = row_pair
331
+
332
+ # SNR formula
333
+ formula1 = f"=IFERROR({base_col}{row1}/{std_col}{row1},\"\")"
334
+ formula_col = get_column_letter(column_index_from_string(col_group[-1]) + 1)
335
+ cell1 = ws[f"{formula_col}{row1}"]
336
+ cell1.value = formula1
337
+ cell1.font = red_font
338
+ cell1.alignment = openpyxl.styles.Alignment(horizontal='center')
339
+
340
+ # CNR formula
341
+ formula2 = f"=IFERROR(({base_col}{row1}-{base_col}{row2})/{std_col}{row2},\"\")"
342
+ cell2 = ws[f"{formula_col}{row2}"]
343
+ cell2.value = formula2
344
+ cell2.font = red_font
345
+ cell2.alignment = openpyxl.styles.Alignment(horizontal='center')
346
+
347
+ logger.debug(f"Added formulas for rows {row1},{row2} in column {formula_col}")
348
+ except Exception as e:
349
+ logger.error(f"Error adding formulas: {str(e)}")
350
+
351
  def save_formatted_results(self, output_path):
352
  try:
353
  if not self.results:
 
425
  cell = ws[f"{col}{row}"]
426
  if cell.value is not None:
427
  cell.alignment = center_alignment
 
428
  # StdDev Averages
429
  current_row = 32
430
  stddev_header = ws.cell(row=current_row, column=1, value="StdDev Averages")
 
781
  print(f"Error launching application: {str(e)}")
782
  logger.error(f"Error launching application: {str(e)}")
783
  logger.error(traceback.format_exc())
784
+ raise e