Wie trenne ich jedes Blatt eines mehrblättrigen Kollimators auf einem Dicom-Bild? [geschlossen]Python

Python-Programme
Anonymous
 Wie trenne ich jedes Blatt eines mehrblättrigen Kollimators auf einem Dicom-Bild? [geschlossen]

Post by Anonymous »

Ich versuche, jedes Blatt aus dem folgenden DICOM-Bild zu trennen. Ich habe Vorverarbeitungstechniken ausprobiert, schaffe es aber nicht, sie visuell zu trennen:
Image

Image

Jede Beule ist ein Blatt und ich muss sie einzeln isolieren, um sie zu zählen (jede von ihnen sollte die gleiche Größe haben):
Image

Code: Select all

import os
import glob
import cv2
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
import pydicom
from tqdm import tqdm

%matplotlib inline

# Path to your DICOM file as .dcm (i can provide it)
dicom_file = r''

dicom_data = pydicom.dcmread(dicom_file)
image_array = dicom_data.pixel_array.astype(np.float32)

print(f"Image shape: {image_array.shape}")
print(f"Min value: {image_array.min()}")
print(f"Max value: {image_array.max()}")

plt.figure(figsize=(6, 6))
plt.imshow(image_array, cmap='gray')
plt.title('Original DICOM Image')
plt.colorbar()
plt.axis('off')
plt.tight_layout()
plt.show()

def normalize_image(image):
min_val = image.min()
max_val = image.max()
normalized = (image - min_val) / (max_val - min_val)
return normalized

normalized_img = normalize_image(image_array)

plt.figure(figsize=(12, 4))
plt.subplot(1, 2, 1)
plt.imshow(image_array, cmap='gray')
plt.title('Original')
plt.axis('off')

img_8bit_for_contrast = cv2.normalize(normalized_img, None, 0, 255, cv2.NORM_MINMAX).astype(np.uint8)

clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
clahe_img = clahe.apply(img_8bit_for_contrast)

hist_eq_img = cv2.equalizeHist(img_8bit_for_contrast)

gamma = 1.5
inv_gamma = 1.0 / gamma
table = np.array([((i / 255.0) ** inv_gamma) * 255 for i in np.arange(0, 256)]).astype(np.uint8)
gamma_corrected = cv2.LUT(img_8bit_for_contrast, table)

adaptive_thresh = cv2.adaptiveThreshold(img_8bit_for_contrast, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
cv2.THRESH_BINARY, 11, 2)

power_law = np.power(normalized_img, 0.5) * 255
power_law = power_law.astype(np.uint8)

# Display all contrast enhancement methods
fig, axes = plt.subplots(2, 3, figsize=(18, 10))

axes[0, 0].imshow(img_8bit_for_contrast, cmap='gray')
axes[0, 0].set_title('Original (8-bit)', fontsize=12, fontweight='bold')
axes[0, 0].axis('off')

axes[0, 1].imshow(clahe_img, cmap='gray')
axes[0, 1].set_title('CLAHE', fontsize=12, fontweight='bold')
axes[0, 1].axis('off')

axes[0, 2].imshow(hist_eq_img, cmap='gray')
axes[0, 2].set_title('Histogram Equalization', fontsize=12, fontweight='bold')
axes[0, 2].axis('off')

axes[1, 0].imshow(gamma_corrected, cmap='gray')
axes[1, 0].set_title('Gamma Correction (1.5)', fontsize=12, fontweight='bold')
axes[1, 0].axis('off')

axes[1, 1].imshow(adaptive_thresh, cmap='gray')
axes[1, 1].set_title('Adaptive Thresholding', fontsize=12, fontweight='bold')
axes[1, 1].axis('off')

axes[1, 2].imshow(power_law, cmap='gray')
axes[1, 2].set_title('Power Law (0.5)', fontsize=12, fontweight='bold')
axes[1, 2].axis('off')

plt.tight_layout()
plt.show()
  • Sprache: Python 3
  • Bibliotheken: OpenCV, NumPy, Matplotlib, PyDICOM
  • Umgebung: Jupyter Notebook
  • Aktuell Ansatz: Normalisierung → CLAHE → Laplace-Schärfung → Kantenerkennung

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post