Update app.py
Browse files
app.py
CHANGED
|
@@ -131,18 +131,23 @@ class DicomAnalyzer:
|
|
| 131 |
# Get image dimensions
|
| 132 |
height, width = raw_image.shape[:2]
|
| 133 |
|
| 134 |
-
#
|
| 135 |
clicked_x = evt.index[0]
|
| 136 |
clicked_y = evt.index[1]
|
| 137 |
|
| 138 |
-
#
|
| 139 |
-
x = int(clicked_x)
|
| 140 |
-
y = int(clicked_y)
|
| 141 |
-
|
| 142 |
if self.zoom_factor != 1.0:
|
| 143 |
-
#
|
| 144 |
x = int((clicked_x + self.pan_x) / self.zoom_factor)
|
| 145 |
y = int((clicked_y + self.pan_y) / self.zoom_factor)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
# Ensure coordinates are within bounds
|
| 148 |
x = max(0, min(x, width-1))
|
|
@@ -157,15 +162,15 @@ class DicomAnalyzer:
|
|
| 157 |
)
|
| 158 |
mask[distance_from_center <= radius] = 1
|
| 159 |
|
| 160 |
-
# Get ROI pixels from raw image
|
| 161 |
roi_pixels = raw_image[mask == 1]
|
| 162 |
|
| 163 |
-
# Calculate statistics
|
| 164 |
pixel_spacing = float(self.dicom_data.PixelSpacing[0])
|
| 165 |
area_pixels = np.sum(mask)
|
| 166 |
area_mm2 = area_pixels * (pixel_spacing ** 2)
|
| 167 |
|
| 168 |
-
#
|
| 169 |
mean = np.mean(roi_pixels)
|
| 170 |
stddev = np.std(roi_pixels)
|
| 171 |
min_val = np.min(roi_pixels)
|
|
@@ -185,8 +190,8 @@ class DicomAnalyzer:
|
|
| 185 |
self.marks.append((x, y, self.circle_diameter))
|
| 186 |
|
| 187 |
# Debug information
|
| 188 |
-
print(f"
|
| 189 |
-
print(f"Adjusted
|
| 190 |
print(f"Zoom factor: {self.zoom_factor}")
|
| 191 |
print(f"Pan: ({self.pan_x}, {self.pan_y})")
|
| 192 |
print(f"ROI Statistics: Mean={mean:.3f}, StdDev={stddev:.3f}")
|
|
|
|
| 131 |
# Get image dimensions
|
| 132 |
height, width = raw_image.shape[:2]
|
| 133 |
|
| 134 |
+
# Get clicked coordinates
|
| 135 |
clicked_x = evt.index[0]
|
| 136 |
clicked_y = evt.index[1]
|
| 137 |
|
| 138 |
+
# ImageJ coordinate system conversion
|
|
|
|
|
|
|
|
|
|
| 139 |
if self.zoom_factor != 1.0:
|
| 140 |
+
# Convert from display coordinates to image coordinates
|
| 141 |
x = int((clicked_x + self.pan_x) / self.zoom_factor)
|
| 142 |
y = int((clicked_y + self.pan_y) / self.zoom_factor)
|
| 143 |
+
else:
|
| 144 |
+
# Direct mapping for no zoom
|
| 145 |
+
x = int(clicked_x)
|
| 146 |
+
y = int(clicked_y)
|
| 147 |
+
|
| 148 |
+
# Offset correction for ImageJ compatibility
|
| 149 |
+
x = x + 4 # Adjust these offset values based on testing
|
| 150 |
+
y = y + 4 # Adjust these offset values based on testing
|
| 151 |
|
| 152 |
# Ensure coordinates are within bounds
|
| 153 |
x = max(0, min(x, width-1))
|
|
|
|
| 162 |
)
|
| 163 |
mask[distance_from_center <= radius] = 1
|
| 164 |
|
| 165 |
+
# Get ROI pixels directly from raw image
|
| 166 |
roi_pixels = raw_image[mask == 1]
|
| 167 |
|
| 168 |
+
# Calculate statistics from raw values
|
| 169 |
pixel_spacing = float(self.dicom_data.PixelSpacing[0])
|
| 170 |
area_pixels = np.sum(mask)
|
| 171 |
area_mm2 = area_pixels * (pixel_spacing ** 2)
|
| 172 |
|
| 173 |
+
# Calculate statistics
|
| 174 |
mean = np.mean(roi_pixels)
|
| 175 |
stddev = np.std(roi_pixels)
|
| 176 |
min_val = np.min(roi_pixels)
|
|
|
|
| 190 |
self.marks.append((x, y, self.circle_diameter))
|
| 191 |
|
| 192 |
# Debug information
|
| 193 |
+
print(f"Original click: ({clicked_x}, {clicked_y})")
|
| 194 |
+
print(f"Adjusted coordinates: ({x}, {y})")
|
| 195 |
print(f"Zoom factor: {self.zoom_factor}")
|
| 196 |
print(f"Pan: ({self.pan_x}, {self.pan_y})")
|
| 197 |
print(f"ROI Statistics: Mean={mean:.3f}, StdDev={stddev:.3f}")
|