Update app.py
Browse files
app.py
CHANGED
|
@@ -143,24 +143,22 @@ class DicomAnalyzer:
|
|
| 143 |
y = int(round(y))
|
| 144 |
|
| 145 |
# Get image dimensions
|
| 146 |
-
height, width = self.
|
| 147 |
|
| 148 |
# Create mask exactly as ImageJ does
|
| 149 |
Y, X = np.ogrid[:height, :width]
|
| 150 |
-
center_x = x
|
| 151 |
-
center_y = y
|
| 152 |
|
| 153 |
-
# ImageJ
|
| 154 |
-
radius = self.circle_diameter / 2.0
|
| 155 |
|
| 156 |
-
#
|
| 157 |
-
dx = X -
|
| 158 |
-
dy = Y -
|
| 159 |
-
dist_squared = dx
|
| 160 |
-
mask = dist_squared <=
|
| 161 |
|
| 162 |
-
# Get ROI pixels
|
| 163 |
-
roi_pixels = self.
|
| 164 |
|
| 165 |
if len(roi_pixels) == 0:
|
| 166 |
return self.display_image, "Error: No pixels selected"
|
|
@@ -168,11 +166,11 @@ class DicomAnalyzer:
|
|
| 168 |
# Get pixel spacing (mm/pixel)
|
| 169 |
pixel_spacing = float(self.dicom_data.PixelSpacing[0])
|
| 170 |
|
| 171 |
-
# Calculate
|
| 172 |
n_pixels = np.sum(mask)
|
| 173 |
area = n_pixels * (pixel_spacing ** 2)
|
| 174 |
|
| 175 |
-
#
|
| 176 |
mean_value = np.mean(roi_pixels)
|
| 177 |
std_dev = np.std(roi_pixels, ddof=1) # ImageJ uses n-1
|
| 178 |
min_val = np.min(roi_pixels)
|
|
@@ -225,7 +223,7 @@ class DicomAnalyzer:
|
|
| 225 |
for x, y, diameter in self.marks:
|
| 226 |
zoomed_x = int(x * self.zoom_factor)
|
| 227 |
zoomed_y = int(y * self.zoom_factor)
|
| 228 |
-
zoomed_radius = int((diameter/2) * self.zoom_factor)
|
| 229 |
|
| 230 |
# Draw main circle
|
| 231 |
cv2.circle(zoomed_bgr,
|
|
|
|
| 143 |
y = int(round(y))
|
| 144 |
|
| 145 |
# Get image dimensions
|
| 146 |
+
height, width = self.original_image.shape[:2]
|
| 147 |
|
| 148 |
# Create mask exactly as ImageJ does
|
| 149 |
Y, X = np.ogrid[:height, :width]
|
|
|
|
|
|
|
| 150 |
|
| 151 |
+
# ImageJ's circle creation method
|
| 152 |
+
radius = (self.circle_diameter - 1) / 2.0
|
| 153 |
|
| 154 |
+
# Calculate distances using ImageJ's method
|
| 155 |
+
dx = X - x
|
| 156 |
+
dy = Y - y
|
| 157 |
+
dist_squared = dx*dx + dy*dy
|
| 158 |
+
mask = dist_squared <= radius*radius
|
| 159 |
|
| 160 |
+
# Get ROI pixels using original image values
|
| 161 |
+
roi_pixels = self.original_image[mask]
|
| 162 |
|
| 163 |
if len(roi_pixels) == 0:
|
| 164 |
return self.display_image, "Error: No pixels selected"
|
|
|
|
| 166 |
# Get pixel spacing (mm/pixel)
|
| 167 |
pixel_spacing = float(self.dicom_data.PixelSpacing[0])
|
| 168 |
|
| 169 |
+
# Calculate area (this is correct)
|
| 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) # ImageJ uses n-1
|
| 176 |
min_val = np.min(roi_pixels)
|
|
|
|
| 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 |
+
zoomed_radius = int(((diameter - 1) / 2) * self.zoom_factor) # ImageJ radius
|
| 227 |
|
| 228 |
# Draw main circle
|
| 229 |
cv2.circle(zoomed_bgr,
|