<<<<<<< HEAD
- Overview
- Key Features
- System Architecture
- Security Implementation
- User Roles & Permissions
- Technical Implementation
- Machine Learning Model
- API Reference
- Database Schema
- Libraries & Dependencies
- Installation & Setup
- Development Guidelines
- Deployment
- Troubleshooting
- License
The Medical Image Processing System is a comprehensive platform designed for secure handling, processing, and analysis of sensitive medical images. The system employs state-of-the-art object detection, image processing, and encryption technologies to ensure patient data privacy while providing authorized medical professionals with the tools they need for diagnosis and treatment.
This system addresses the critical challenge in medical imaging: balancing accessibility for healthcare professionals with strict privacy requirements for patient data. By automatically detecting and encrypting sensitive regions within medical images, the system allows for secure sharing and storage of medical data.
- Selective Encryption: Automatically identifies and encrypts only sensitive regions in medical images
- AES-256-CBC Encryption: Military-grade encryption for all sensitive data
- Diffie-Hellman Key Exchange: Secure protocol for establishing encryption keys
- Role-Based Access Control: Granular permissions based on user roles
- Audit Logging: Comprehensive tracking of all system activities
- YOLO-based Object Detection: State-of-the-art AI model for identifying sensitive regions
- Automatic Region Extraction: Precise cropping of detected sensitive areas
- Image Restoration: On-demand reconstruction of original images for authorized users
- Format Support: Handles JPEG, PNG, and other common medical image formats
- Batch Processing: Capability to process multiple images efficiently
- Entropy Analysis: Advanced metrics for assessing image information content
- Similarity Comparison: Tools to compare original and processed images
- Confidence Scoring: Reliability metrics for detection results
- Processing Statistics: Performance metrics for system optimization
- Intuitive Interfaces: Separate UIs tailored for lab technicians and doctors
- Real-time Processing: Immediate feedback on uploaded images
- Responsive Design: Access from various devices and screen sizes
- Search & Filter: Powerful tools to locate patient records and images
The system follows a modern Django-based architecture with the following components:
-
Authentication Service:
- User management and authentication
- JWT token handling
- Diffie-Hellman key exchange implementation
- Role-based permission enforcement
-
Patient Management Service:
- Patient record CRUD operations
- Data validation and sanitization
- Patient history tracking
- Relationship management between patients and images
-
Image Processing Pipeline:
- Image upload and validation
- YOLO model integration for object detection
- Region extraction and processing
- Encryption/decryption operations
- Image storage management
-
Admin Service:
- System configuration management
- User administration
- Monitoring and reporting tools
- Audit log access
- Lab technician uploads patient image
- Authentication service validates user permissions
- Image processing pipeline detects sensitive regions
- Detected regions are encrypted with AES-256
- Processed image and encrypted regions are stored
- Doctor requests access to patient image
- Authentication service validates doctor's permissions
- Encrypted regions are decrypted for authorized viewing
- Algorithm: AES-256-CBC (Advanced Encryption Standard with 256-bit keys in Cipher Block Chaining mode)
- Key Management: Secure key generation and distribution using Diffie-Hellman protocol
- Initialization Vectors: Random 16-byte IVs for each encryption operation
- Padding: PKCS#7 padding for proper block alignment
- Token-based Authentication: JWT (JSON Web Tokens) with appropriate expiration
- Password Security: Bcrypt hashing with salt for password storage
- Multi-factor Authentication: Optional 2FA for enhanced security
- Session Management: Secure handling of user sessions with appropriate timeouts
- In Transit: TLS/SSL encryption for all data transmission
- At Rest: Encrypted storage for sensitive information
- Key Security: Secure key management with proper access controls
- Data Isolation: Proper separation between patient data
- Permissions:
- Upload new patient images
- Create and update patient records
- View processing results (blurred and grid images)
- Access non-sensitive patient information
- Restrictions:
- Cannot view decrypted sensitive regions
- Cannot modify processed images
- Limited access to patient history
- Permissions:
- View all patient records
- Access and decrypt sensitive regions
- Generate restored images on demand
- Analyze image metrics and statistics
- Add medical notes to patient records
- Restrictions:
- Cannot modify original or processed images
- Limited administrative functions
- Permissions:
- Manage user accounts and permissions
- Configure system parameters
- Access audit logs and system metrics
- Manage encryption settings
- Restrictions:
- Cannot directly access patient data without proper role
- Actions are logged for accountability
- Supported formats: JPEG, PNG, DICOM
- Size limitations: Up to 20MB per image
- Validation checks: Format verification, dimension constraints, metadata sanitization
- Model: YOLOv8 (You Only Look Once)
- Configuration:
- Confidence threshold: 0.25 (configurable)
- Non-maximum suppression IoU threshold: 0.45
- Classes: Configured for specific sensitive medical regions
- Performance:
- Average inference time: ~200ms per image
- Precision: >0.92 for supported classes
- Recall: >0.90 for supported classes
- Automatic cropping based on detection bounding boxes
- Padding addition for privacy enhancement
- Format preservation of original image
- Metadata handling and sanitization
- Region-specific encryption with unique IVs
- Original filename and format preservation
- Entropy calculation for quality assurance
- Performance metrics collection
- Efficient storage of blurred images, grid representations, and encrypted regions
- On-demand decryption for authorized users
- Caching system for improved performance
- Backup and recovery mechanisms
- Client initiates key exchange request
- Server generates DH parameters (p, g) and server keypair
- Server sends public parameters and public key to client
- Client generates client keypair using server parameters
- Client sends public key to server
- Both parties independently compute the shared secret
- Shared secret is hashed to derive AES-256 encryption key
- Generate random 16-byte Initialization Vector
- Pad data using PKCS#7 to match AES block size
- Encrypt data using AES-256-CBC with derived key and IV
- Prepend IV to encrypted data for storage
- Store encryption metadata (format, original filename)
- Extract IV from first 16 bytes of encrypted data
- Retrieve encryption key for authorized user
- Decrypt data using AES-256-CBC
- Remove padding from decrypted data
- Verify data integrity through header checks
- Base Model: YOLOv8n (nano variant)
- Framework: PyTorch
- Size: 50MB
- Architecture: CSP-Darknet backbone with additional cross-stage partial connections
- Dataset: Proprietary medical imaging dataset with annotated sensitive regions
- Annotations: 10,000+ bounding boxes across multiple classes
- Training Regime:
- Epochs: 100
- Batch size: 16
- Optimizer: SGD with momentum
- Learning rate: 0.01 with cosine annealing
- Data augmentation: Random flip, rotation, color jittering
- mAP@0.5: 0.94
- mAP@0.5:0.95: 0.86
- Inference Speed: 15ms per image on GPU, 200ms on CPU
- Classes: Configurable based on medical specialty requirements
- Located in
/model/best.pt
- Loaded dynamically at system startup
- Configurable inference parameters via environment variables
- GPU acceleration when available, graceful fallback to CPU
- Periodic retraining with new data
- Performance monitoring and drift detection
- Version control for model files
- A/B testing framework for model improvements
POST /api/auth/register/
- Request Body:
{ "username": "doctor_smith", "email": "smith@hospital.com", "password": "secure_password", "role": "doctor" }
- Response: User details with JWT token
POST /api/auth/token/
- Request Body:
{ "username": "doctor_smith", "password": "secure_password" }
- Response: JWT access and refresh tokens
GET /api/auth/key-exchange/
POST /api/auth/key-exchange/
- GET Response: DH parameters and server public key
- POST Request Body:
{ "client_public_key": "large_integer_value" }
- POST Response: Success confirmation
POST /api/patients/
- Request Body: Multipart form with patient details and image
- Response: Patient ID and processing status
GET /api/patients/{id}/
- Response: Patient information and latest image summary
GET /api/patients/{id}/images/
- Response: List of all processed images for patient
GET /api/images/{id}/restore/
- Query Parameters:
format
: Output format (png/jpeg)enhance
: Enable enhancement (true/false)
- Response: Restored image file
GET /api/images/{id}/regions/
- Response: List of detected regions with metadata
GET /api/regions/{id}/
- Response: Decrypted region image file
class Patient(models.Model):
id = models.CharField(primary_key=True, max_length=50)
name = models.CharField(max_length=100)
age = models.IntegerField()
note = models.TextField(blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class ProcessedImage(models.Model):
patient = models.ForeignKey(Patient, on_delete=models.CASCADE)
blurred_image = models.ImageField(upload_to='patient_images/blurred/')
grid_image = models.ImageField(upload_to='patient_images/grid/')
restored_image = models.ImageField(upload_to='patient_images/restored/')
enhanced = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
original_entropy = models.FloatField(null=True)
encrypted_entropy = models.FloatField(null=True)
encryption_time = models.FloatField(null=True)
decryption_time = models.FloatField(null=True)
class CroppedRegion(models.Model):
processed_image = models.ForeignKey(ProcessedImage, on_delete=models.CASCADE)
class_name = models.CharField(max_length=50)
confidence = models.FloatField()
x1, y1, x2, y2 = models.IntegerField() # Coordinates
cropped_image_data = models.BinaryField() # Encrypted data
original_filename = models.CharField(max_length=255)
image_format = models.CharField(max_length=10, default='JPEG')
created_at = models.DateTimeField(auto_now_add=True)
class ImageFingerprint(models.Model):
processed_image = models.OneToOneField(ProcessedImage)
color_histogram = models.BinaryField()
avg_hash = models.CharField(max_length=64)
phash = models.CharField(max_length=64)
created_at = models.DateTimeField(auto_now_add=True)
- Django 4.2+: Web framework for backend development
- Django REST Framework 3.14+: API development toolkit
- PyTorch 2.0+: Deep learning framework
- Ultralytics YOLOv8: Object detection model
- OpenCV 4.7+: Computer vision operations
- Image processing
- Contour detection
- Image transformations
- NumPy 1.24+: Numerical computations
- SciPy 1.10+: Scientific computing
- Entropy calculations
- Statistical operations
- Pillow 9.5+: Image processing library
- ImageHash 4.3+: Perceptual image hashing
- Cryptography 39.0+: Cryptographic recipes and primitives
- Diffie-Hellman key exchange
- Key derivation functions
- PyCryptodome 3.17+: Cryptographic library
- AES-256-CBC implementation
- PKCS#7 padding
- PyJWT 2.6+: JSON Web Token implementation
- Django Simple JWT 5.2+: JWT authentication for Django REST Framework
- PostgreSQL 14+: Primary database
- psycopg2-binary 2.9+: PostgreSQL adapter for Python
- Redis 7.0+: Caching and key storage
- django-redis 5.2+: Redis integration for Django
- pytest 7.3+: Testing framework
- pytest-django 4.5+: Django integration for pytest
- coverage 7.2+: Code coverage measurement
- python-dotenv 1.0+: Environment variable management
- django-filter 23.1+: Filtering for Django querysets
- django-cors-headers 4.0+: CORS headers for Django
- drf-yasg 1.21+: Swagger/OpenAPI documentation
- gunicorn 20.1+: WSGI HTTP server
- whitenoise 6.4+: Static file serving
- Bootstrap 5.2+: CSS framework
- Chart.js 4.2+: JavaScript charting library
- Axios 1.3+: HTTP client
- black: Python code formatter
- flake8: Code linter
- isort: Import sorter
- pre-commit: Git hooks manager
- SMTP Server: For email notifications
- S3-compatible Storage (optional): For scalable image storage
- Python 3.8+
- CUDA 11.7+ (for GPU acceleration)
- Node.js 18+ (for frontend development) =======
81657d024ef1c9f141b642460666c15a9e66275b