Update app.py
Browse files
app.py
CHANGED
|
@@ -131,33 +131,35 @@ class DicomAnalyzer:
|
|
| 131 |
clicked_x = evt.index[0]
|
| 132 |
clicked_y = evt.index[1]
|
| 133 |
|
| 134 |
-
# Transform coordinates
|
| 135 |
x = clicked_x + self.pan_x
|
| 136 |
y = clicked_y + self.pan_y
|
| 137 |
if self.zoom_factor != 1.0:
|
| 138 |
x = x / self.zoom_factor
|
| 139 |
y = y / self.zoom_factor
|
| 140 |
|
| 141 |
-
# ImageJ uses integer coordinates
|
| 142 |
x = int(round(x))
|
| 143 |
y = int(round(y))
|
| 144 |
|
| 145 |
# Get image dimensions
|
| 146 |
height, width = self.original_image.shape[:2]
|
| 147 |
|
| 148 |
-
# Create mask
|
| 149 |
Y, X = np.ogrid[:height, :width]
|
| 150 |
|
| 151 |
-
#
|
| 152 |
-
radius = (self.circle_diameter
|
|
|
|
| 153 |
|
| 154 |
-
# Calculate distances
|
| 155 |
dx = X - x
|
| 156 |
dy = Y - y
|
| 157 |
dist_squared = dx*dx + dy*dy
|
| 158 |
-
mask = dist_squared <= radius*radius
|
| 159 |
|
| 160 |
-
#
|
|
|
|
|
|
|
|
|
|
| 161 |
roi_pixels = self.original_image[mask]
|
| 162 |
|
| 163 |
if len(roi_pixels) == 0:
|
|
@@ -166,19 +168,17 @@ class DicomAnalyzer:
|
|
| 166 |
# Get pixel spacing (mm/pixel)
|
| 167 |
pixel_spacing = float(self.dicom_data.PixelSpacing[0])
|
| 168 |
|
| 169 |
-
# Calculate
|
| 170 |
n_pixels = np.sum(mask)
|
| 171 |
area = n_pixels * (pixel_spacing ** 2)
|
| 172 |
-
|
| 173 |
-
# Calculate statistics using original pixel values
|
| 174 |
mean_value = np.mean(roi_pixels)
|
| 175 |
-
std_dev = np.std(roi_pixels, ddof=1)
|
| 176 |
min_val = np.min(roi_pixels)
|
| 177 |
max_val = np.max(roi_pixels)
|
| 178 |
|
| 179 |
-
|
| 180 |
-
print(f"
|
| 181 |
-
print(f"
|
| 182 |
print(f"Pixel count: {n_pixels}")
|
| 183 |
print(f"Area: {area:.3f} mm²")
|
| 184 |
print(f"Mean: {mean_value:.3f}")
|
|
@@ -186,7 +186,6 @@ class DicomAnalyzer:
|
|
| 186 |
print(f"Min: {min_val}")
|
| 187 |
print(f"Max: {max_val}")
|
| 188 |
|
| 189 |
-
# Store results
|
| 190 |
result = {
|
| 191 |
'Area (mm²)': f"{area:.3f}",
|
| 192 |
'Mean': f"{mean_value:.3f}",
|
|
@@ -223,7 +222,8 @@ class DicomAnalyzer:
|
|
| 223 |
for x, y, diameter in self.marks:
|
| 224 |
zoomed_x = int(x * self.zoom_factor)
|
| 225 |
zoomed_y = int(y * self.zoom_factor)
|
| 226 |
-
|
|
|
|
| 227 |
|
| 228 |
# Draw main circle
|
| 229 |
cv2.circle(zoomed_bgr,
|
|
|
|
| 131 |
clicked_x = evt.index[0]
|
| 132 |
clicked_y = evt.index[1]
|
| 133 |
|
| 134 |
+
# Transform coordinates
|
| 135 |
x = clicked_x + self.pan_x
|
| 136 |
y = clicked_y + self.pan_y
|
| 137 |
if self.zoom_factor != 1.0:
|
| 138 |
x = x / self.zoom_factor
|
| 139 |
y = y / self.zoom_factor
|
| 140 |
|
|
|
|
| 141 |
x = int(round(x))
|
| 142 |
y = int(round(y))
|
| 143 |
|
| 144 |
# Get image dimensions
|
| 145 |
height, width = self.original_image.shape[:2]
|
| 146 |
|
| 147 |
+
# Create mask with larger radius calculation
|
| 148 |
Y, X = np.ogrid[:height, :width]
|
| 149 |
|
| 150 |
+
# Increase effective radius to include boundary pixels
|
| 151 |
+
radius = (self.circle_diameter / 2.0) + 0.5 # Add 0.5 to include boundary pixels
|
| 152 |
+
r_squared = radius * radius
|
| 153 |
|
| 154 |
+
# Calculate distances with more inclusive boundary
|
| 155 |
dx = X - x
|
| 156 |
dy = Y - y
|
| 157 |
dist_squared = dx*dx + dy*dy
|
|
|
|
| 158 |
|
| 159 |
+
# Include slightly more pixels in the mask
|
| 160 |
+
mask = dist_squared <= (r_squared + 0.25) # Add small tolerance
|
| 161 |
+
|
| 162 |
+
# Get ROI pixels
|
| 163 |
roi_pixels = self.original_image[mask]
|
| 164 |
|
| 165 |
if len(roi_pixels) == 0:
|
|
|
|
| 168 |
# Get pixel spacing (mm/pixel)
|
| 169 |
pixel_spacing = float(self.dicom_data.PixelSpacing[0])
|
| 170 |
|
| 171 |
+
# Calculate statistics
|
| 172 |
n_pixels = np.sum(mask)
|
| 173 |
area = n_pixels * (pixel_spacing ** 2)
|
|
|
|
|
|
|
| 174 |
mean_value = np.mean(roi_pixels)
|
| 175 |
+
std_dev = np.std(roi_pixels, ddof=1)
|
| 176 |
min_val = np.min(roi_pixels)
|
| 177 |
max_val = np.max(roi_pixels)
|
| 178 |
|
| 179 |
+
print(f"\nEnhanced Analysis:")
|
| 180 |
+
print(f"Position: ({x}, {y})")
|
| 181 |
+
print(f"Effective Radius: {radius}")
|
| 182 |
print(f"Pixel count: {n_pixels}")
|
| 183 |
print(f"Area: {area:.3f} mm²")
|
| 184 |
print(f"Mean: {mean_value:.3f}")
|
|
|
|
| 186 |
print(f"Min: {min_val}")
|
| 187 |
print(f"Max: {max_val}")
|
| 188 |
|
|
|
|
| 189 |
result = {
|
| 190 |
'Area (mm²)': f"{area:.3f}",
|
| 191 |
'Mean': f"{mean_value:.3f}",
|
|
|
|
| 222 |
for x, y, diameter in self.marks:
|
| 223 |
zoomed_x = int(x * self.zoom_factor)
|
| 224 |
zoomed_y = int(y * self.zoom_factor)
|
| 225 |
+
# Use enhanced radius for display
|
| 226 |
+
zoomed_radius = int(((diameter/2.0 + 0.5) * self.zoom_factor))
|
| 227 |
|
| 228 |
# Draw main circle
|
| 229 |
cv2.circle(zoomed_bgr,
|