help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
satellite-images
RSK World
satellite-images
Satellite Images Dataset - Land Cover Classification + Building Detection + Remote Sensing + Geospatial Analysis
satellite-images
  • __pycache__
  • data
  • visualizations
  • .gitignore780 B
  • ADVANCED_FEATURES.md7.2 KB
  • ATTRIBUTION.md1.5 KB
  • DATA_SUMMARY.md3.9 KB
  • DOWNLOAD_REAL_DATA_GUIDE.md3.4 KB
  • ERROR_FIXES_SUMMARY.md3.2 KB
  • GITHUB_RELEASE_INSTRUCTIONS.md4.9 KB
  • LICENSE1.2 KB
  • PROJECT_INFO.md3 KB
  • QUICK_DOWNLOAD_GUIDE.md2.1 KB
  • QUICK_START_ADVANCED.md2 KB
  • README.md8.1 KB
  • RELEASE_NOTES_v1.0.0.md7.1 KB
  • advanced_example.py11 KB
  • advanced_processing.py17.3 KB
  • advanced_visualization.py15.5 KB
  • batch_processing.py11.9 KB
  • batch_processor.py10.8 KB
  • check_errors.py6.9 KB
  • config.py1.1 KB
  • create_placeholder_image.py3.5 KB
  • create_sample_images.py5.3 KB
  • data_loader.py6 KB
  • download_real_images.py5 KB
  • download_real_satellite_data.py8.4 KB
  • download_with_landsatxplore.py4.6 KB
  • download_with_sentinelsat.py6 KB
  • enhanced_real_image_downloader.py17.8 KB
  • example_usage.py4.3 KB
  • generate_sample_data.py7.2 KB
  • get_real_satellite_data.py9.6 KB
  • index.html18.5 KB
  • ml_features.py11.8 KB
  • ml_integration.py13.6 KB
  • process_images.py7 KB
  • real_image_downloader.py15.7 KB
  • requirements.txt632 B
  • requirements_download.txt474 B
  • satellite-images.png2.6 MB
  • setup.py1.6 KB
  • visualize.py5.8 KB
train_model.py.keepbatch_processing.pytasks_controller_test.rbtrain_model.pybatch_processor.py
batch_processing.py
Raw Download
Find: Go to:
#!/usr/bin/env python3
"""
Satellite Image Dataset - Batch Processing and Augmentation
Created by: RSK World
Website: https://rskworld.in
Email: help@rskworld.in
Phone: +91 93305 39277

Batch processing features:
- Process multiple images
- Data augmentation
- Parallel processing
- Export utilities
"""

import cv2
import numpy as np
from pathlib import Path
from typing import List, Dict, Tuple, Optional, Callable
import json
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
import multiprocessing as mp
from tqdm import tqdm
import random


class BatchProcessor:
    """
    Batch processing utilities for satellite images.
    Created by: RSK World (https://rskworld.in)
    """
    
    def __init__(self, num_workers: Optional[int] = None):
        """
        Initialize batch processor.
        
        Args:
            num_workers: Number of parallel workers (None = auto)
        """
        self.num_workers = num_workers or mp.cpu_count()
    
    def process_batch(self, image_paths: List[Path],
                     processor_func: Callable,
                     output_dir: Optional[Path] = None,
                     **kwargs) -> List[Dict]:
        """
        Process a batch of images.
        
        Args:
            image_paths: List of image file paths
            processor_func: Function to process each image
            output_dir: Optional output directory
            **kwargs: Additional arguments for processor function
            
        Returns:
            List of processing results
        """
        results = []
        
        print(f"Processing {len(image_paths)} images with {self.num_workers} workers...")
        
        with ThreadPoolExecutor(max_workers=self.num_workers) as executor:
            futures = []
            for img_path in image_paths:
                future = executor.submit(self._process_single, 
                                       img_path, processor_func, output_dir, **kwargs)
                futures.append(future)
            
            for future in tqdm(futures, desc="Processing"):
                try:
                    result = future.result()
                    results.append(result)
                except Exception as e:
                    print(f"Error processing image: {e}")
                    results.append({'error': str(e)})
        
        return results
    
    def _process_single(self, img_path: Path, processor_func: Callable,
                       output_dir: Optional[Path], **kwargs) -> Dict:
        """Process a single image."""
        try:
            # Load image
            image = cv2.imread(str(img_path))
            if image is None:
                return {'error': f'Could not load {img_path}'}
            
            image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
            
            # Process
            result = processor_func(image, **kwargs)
            
            # Save if output directory provided
            if output_dir:
                output_dir.mkdir(parents=True, exist_ok=True)
                output_path = output_dir / f"{img_path.stem}_processed.png"
                cv2.imwrite(str(output_path), 
                           cv2.cvtColor(result if isinstance(result, np.ndarray) else image, 
                                      cv2.COLOR_RGB2BGR))
            
            return {
                'input': str(img_path),
                'output': str(output_path) if output_dir else None,
                'success': True
            }
        except Exception as e:
            return {'error': str(e), 'input': str(img_path)}


class ImageAugmenter:
    """
    Image augmentation utilities for satellite images.
    Created by: RSK World (https://rskworld.in)
    """
    
    def __init__(self):
        """Initialize augmenter."""
        pass
    
    def augment_image(self, image: np.ndarray, 
                     augmentations: List[str] = None) -> List[np.ndarray]:
        """
        Apply multiple augmentations to an image.
        
        Args:
            image: Input image
            augmentations: List of augmentation names
            
        Returns:
            List of augmented images
        """
        if augmentations is None:
            augmentations = ['flip_horizontal', 'flip_vertical', 'rotate', 
                           'brightness', 'contrast', 'noise']
        
        augmented = []
        
        for aug_name in augmentations:
            try:
                aug_func = getattr(self, f'_{aug_name}')
                aug_img = aug_func(image.copy())
                augmented.append(aug_img)
            except AttributeError:
                print(f"Unknown augmentation: {aug_name}")
        
        return augmented
    
    def _flip_horizontal(self, image: np.ndarray) -> np.ndarray:
        """Flip image horizontally."""
        return cv2.flip(image, 1)
    
    def _flip_vertical(self, image: np.ndarray) -> np.ndarray:
        """Flip image vertically."""
        return cv2.flip(image, 0)
    
    def _rotate(self, image: np.ndarray, angle: float = None) -> np.ndarray:
        """Rotate image."""
        if angle is None:
            angle = random.choice([90, 180, 270])
        
        h, w = image.shape[:2]
        center = (w // 2, h // 2)
        matrix = cv2.getRotationMatrix2D(center, angle, 1.0)
        
        return cv2.warpAffine(image, matrix, (w, h))
    
    def _brightness(self, image: np.ndarray, factor: float = None) -> np.ndarray:
        """Adjust brightness."""
        if factor is None:
            factor = random.uniform(0.7, 1.3)
        
        if len(image.shape) == 3:
            hsv = cv2.cvtColor(image, cv2.COLOR_RGB2HSV)
            hsv[:, :, 2] = np.clip(hsv[:, :, 2] * factor, 0, 255)
            return cv2.cvtColor(hsv, cv2.COLOR_HSV2RGB)
        else:
            return np.clip(image * factor, 0, 255).astype(np.uint8)
    
    def _contrast(self, image: np.ndarray, factor: float = None) -> np.ndarray:
        """Adjust contrast."""
        if factor is None:
            factor = random.uniform(0.8, 1.2)
        
        mean = np.mean(image)
        return np.clip((image - mean) * factor + mean, 0, 255).astype(np.uint8)
    
    def _noise(self, image: np.ndarray, amount: float = None) -> np.ndarray:
        """Add noise."""
        if amount is None:
            amount = random.uniform(0.01, 0.05)
        
        noise = np.random.normal(0, amount * 255, image.shape)
        return np.clip(image.astype(np.float32) + noise, 0, 255).astype(np.uint8)
    
    def _crop(self, image: np.ndarray, crop_size: Tuple[int, int] = None) -> np.ndarray:
        """Random crop."""
        h, w = image.shape[:2]
        if crop_size is None:
            crop_size = (int(h * 0.8), int(w * 0.8))
        
        y = random.randint(0, h - crop_size[0])
        x = random.randint(0, w - crop_size[1])
        
        return image[y:y+crop_size[0], x:x+crop_size[1]]
    
    def _scale(self, image: np.ndarray, scale_factor: float = None) -> np.ndarray:
        """Scale image."""
        if scale_factor is None:
            scale_factor = random.uniform(0.8, 1.2)
        
        h, w = image.shape[:2]
        new_h, new_w = int(h * scale_factor), int(w * scale_factor)
        
        return cv2.resize(image, (new_w, new_h), interpolation=cv2.INTER_LINEAR)
    
    def create_augmented_dataset(self, image_paths: List[Path],
                                output_dir: Path,
                                num_augmentations: int = 5) -> Dict:
        """
        Create augmented dataset from images.
        
        Args:
            image_paths: List of image paths
            output_dir: Output directory
            num_augmentations: Number of augmentations per image
            
        Returns:
            Dictionary with dataset info
        """
        output_dir.mkdir(parents=True, exist_ok=True)
        
        dataset_info = {
            'original_images': len(image_paths),
            'augmentations_per_image': num_augmentations,
            'total_images': len(image_paths) * (1 + num_augmentations),
            'files': []
        }
        
        augmentation_methods = ['flip_horizontal', 'flip_vertical', 'rotate',
                               'brightness', 'contrast', 'noise', 'crop', 'scale']
        
        for img_path in tqdm(image_paths, desc="Augmenting"):
            # Load original
            image = cv2.imread(str(img_path))
            if image is None:
                continue
            
            image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
            
            # Save original
            orig_output = output_dir / f"{img_path.stem}_orig.png"
            cv2.imwrite(str(orig_output), cv2.cvtColor(image, cv2.COLOR_RGB2BGR))
            dataset_info['files'].append(str(orig_output))
            
            # Create augmentations
            selected_augs = random.sample(augmentation_methods, 
                                        min(num_augmentations, len(augmentation_methods)))
            
            for i, aug_name in enumerate(selected_augs):
                try:
                    aug_func = getattr(self, f'_{aug_name}')
                    aug_img = aug_func(image.copy())
                    
                    aug_output = output_dir / f"{img_path.stem}_aug_{i+1}_{aug_name}.png"
                    cv2.imwrite(str(aug_output), 
                               cv2.cvtColor(aug_img, cv2.COLOR_RGB2BGR))
                    dataset_info['files'].append(str(aug_output))
                except Exception as e:
                    print(f"Error applying {aug_name}: {e}")
        
        # Save dataset info
        info_file = output_dir / "augmented_dataset_info.json"
        with open(info_file, 'w') as f:
            json.dump(dataset_info, f, indent=4)
        
        return dataset_info


class ExportUtils:
    """
    Export utilities for processed data.
    Created by: RSK World (https://rskworld.in)
    """
    
    @staticmethod
    def export_to_numpy(images: List[np.ndarray], output_path: Path) -> None:
        """Export images to NumPy array file."""
        array = np.array(images)
        np.save(output_path, array)
        print(f"Exported {len(images)} images to {output_path}")
    
    @staticmethod
    def export_metadata(metadata: List[Dict], output_path: Path) -> None:
        """Export metadata to JSON."""
        with open(output_path, 'w') as f:
            json.dump(metadata, f, indent=4)
        print(f"Exported metadata to {output_path}")
    
    @staticmethod
    def create_manifest(image_paths: List[Path], 
                       output_path: Path,
                       metadata: Optional[List[Dict]] = None) -> None:
        """Create manifest file for dataset."""
        manifest = {
            'total_images': len(image_paths),
            'images': [str(p) for p in image_paths],
            'metadata': metadata or []
        }
        
        with open(output_path, 'w') as f:
            json.dump(manifest, f, indent=4)
        
        print(f"Created manifest at {output_path}")


def main():
    """
    Example usage of batch processing.
    Created by: RSK World (https://rskworld.in)
    """
    print("Batch Processing - Example")
    print("Created by: RSK World (https://rskworld.in)")
    print("-" * 50)
    
    # Example: Process images
    processor = BatchProcessor()
    augmenter = ImageAugmenter()
    
    # Create sample augmentation
    sample_image = np.random.randint(0, 255, (256, 256, 3), dtype=np.uint8)
    augmented = augmenter.augment_image(sample_image, ['flip_horizontal', 'brightness'])
    print(f"Created {len(augmented)} augmented versions")
    
    print("\nBatch processing utilities ready!")


if __name__ == "__main__":
    main()

340 lines•11.9 KB
python
batch_processor.py
Raw Download
Find: Go to:
#!/usr/bin/env python3
"""
Satellite Image Dataset - Batch Processing Utilities
Created by: RSK World
Website: https://rskworld.in
Email: help@rskworld.in
Phone: +91 93305 39277

Batch processing utilities including:
- Batch image processing
- Data augmentation
- Parallel processing
- Progress tracking
"""

import numpy as np
from pathlib import Path
from typing import List, Dict, Callable, Optional, Tuple
import json
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
from tqdm import tqdm
import cv2
from data_loader import SatelliteDatasetLoader
from process_images import SatelliteImageProcessor
from advanced_processing import AdvancedImageProcessor


class BatchProcessor:
    """
    Batch processing utilities for satellite images.
    Created by: RSK World (https://rskworld.in)
    """
    
    def __init__(self, data_dir: str = "data", max_workers: int = 4):
        """
        Initialize batch processor.
        
        Args:
            data_dir: Data directory
            max_workers: Maximum number of worker threads/processes
        """
        self.data_dir = Path(data_dir)
        self.max_workers = max_workers
        self.loader = SatelliteDatasetLoader(str(data_dir))
        self.processor = SatelliteImageProcessor(str(data_dir))
        self.advanced_processor = AdvancedImageProcessor()
    
    def process_batch(self, image_ids: List[str],
                     processing_function: Callable,
                     output_dir: Optional[str] = None,
                     save_results: bool = True) -> List[Dict]:
        """
        Process a batch of images.
        
        Args:
            image_ids: List of image IDs to process
            processing_function: Function to apply to each image
            output_dir: Optional output directory
            save_results: Whether to save processing results
            
        Returns:
            List of processing results
        """
        results = []
        output_path = Path(output_dir) if output_dir else None
        
        if output_path:
            output_path.mkdir(parents=True, exist_ok=True)
        
        print(f"Processing {len(image_ids)} images...")
        print("Created by: RSK World (https://rskworld.in)")
        
        for image_id in tqdm(image_ids, desc="Processing"):
            try:
                # Load image
                image, labels = self.loader.load_image_pair(image_id)
                
                if image is None:
                    results.append({
                        'image_id': image_id,
                        'status': 'failed',
                        'error': 'Image not found'
                    })
                    continue
                
                # Process image
                result = processing_function(image, labels)
                result['image_id'] = image_id
                result['status'] = 'success'
                
                # Save if requested
                if save_results and output_path:
                    result_path = output_path / f"{image_id}_result.json"
                    with open(result_path, 'w') as f:
                        json.dump(result, f, indent=4, default=str)
                
                results.append(result)
                
            except Exception as e:
                results.append({
                    'image_id': image_id,
                    'status': 'failed',
                    'error': str(e)
                })
        
        return results
    
    def process_batch_parallel(self, image_ids: List[str],
                              processing_function: Callable,
                              output_dir: Optional[str] = None,
                              use_processes: bool = False) -> List[Dict]:
        """
        Process batch in parallel.
        
        Args:
            image_ids: List of image IDs
            processing_function: Function to apply
            output_dir: Optional output directory
            use_processes: Use processes instead of threads
            
        Returns:
            List of results
        """
        executor_class = ProcessPoolExecutor if use_processes else ThreadPoolExecutor
        
        def process_single(image_id: str) -> Dict:
            try:
                image, labels = self.loader.load_image_pair(image_id)
                if image is None:
                    return {'image_id': image_id, 'status': 'failed', 'error': 'Image not found'}
                
                result = processing_function(image, labels)
                result['image_id'] = image_id
                result['status'] = 'success'
                return result
            except Exception as e:
                return {'image_id': image_id, 'status': 'failed', 'error': str(e)}
        
        print(f"Processing {len(image_ids)} images in parallel...")
        print("Created by: RSK World (https://rskworld.in)")
        
        results = []
        with executor_class(max_workers=self.max_workers) as executor:
            futures = [executor.submit(process_single, img_id) for img_id in image_ids]
            for future in tqdm(futures, desc="Processing"):
                results.append(future.result())
        
        # Save results
        if output_dir:
            output_path = Path(output_dir)
            output_path.mkdir(parents=True, exist_ok=True)
            results_path = output_path / "batch_results.json"
            with open(results_path, 'w') as f:
                json.dump(results, f, indent=4, default=str)
        
        return results


class DataAugmenter:
    """
    Data augmentation for satellite images.
    Created by: RSK World (https://rskworld.in)
    """
    
    @staticmethod
    def augment_image(image: np.ndarray, augmentation_type: str = 'all') -> List[np.ndarray]:
        """
        Apply data augmentation to image.
        
        Args:
            image: Input image
            augmentation_type: Type of augmentation ('all', 'rotation', 'flip', 'brightness', 'noise')
            
        Returns:
            List of augmented images
        """
        augmented = [image.copy()]
        
        if augmentation_type in ['all', 'rotation']:
            # Rotations
            for angle in [90, 180, 270]:
                center = (image.shape[1] // 2, image.shape[0] // 2)
                matrix = cv2.getRotationMatrix2D(center, angle, 1.0)
                rotated = cv2.warpAffine(image, matrix, (image.shape[1], image.shape[0]))
                augmented.append(rotated)
        
        if augmentation_type in ['all', 'flip']:
            # Flips
            augmented.append(cv2.flip(image, 0))  # Vertical
            augmented.append(cv2.flip(image, 1))  # Horizontal
            augmented.append(cv2.flip(image, -1))  # Both
        
        if augmentation_type in ['all', 'brightness']:
            # Brightness adjustments
            for factor in [0.7, 1.3]:
                bright = np.clip(image * factor, 0, 1 if image.max() <= 1 else 255)
                augmented.append(bright.astype(image.dtype))
        
        if augmentation_type in ['all', 'noise']:
            # Add noise
            noise = np.random.normal(0, 0.05, image.shape)
            noisy = np.clip(image + noise, 0, 1 if image.max() <= 1 else 255)
            augmented.append(noisy.astype(image.dtype))
        
        return augmented
    
    @staticmethod
    def augment_dataset(image_ids: List[str], 
                       loader: SatelliteDatasetLoader,
                       output_dir: str,
                       augmentation_type: str = 'all') -> List[str]:
        """
        Augment entire dataset.
        
        Args:
            image_ids: List of image IDs
            loader: Dataset loader
            output_dir: Output directory
            augmentation_type: Type of augmentation
            
        Returns:
            List of augmented image paths
        """
        output_path = Path(output_dir)
        output_path.mkdir(parents=True, exist_ok=True)
        
        augmented_paths = []
        
        print(f"Augmenting {len(image_ids)} images...")
        print("Created by: RSK World (https://rskworld.in)")
        
        for image_id in tqdm(image_ids, desc="Augmenting"):
            image, labels = loader.load_image_pair(image_id)
            
            if image is None:
                continue
            
            # Normalize for augmentation
            if image.max() > 1:
                image_norm = image.astype(np.float32) / 255.0
            else:
                image_norm = image.astype(np.float32)
            
            # Augment
            augmented_images = DataAugmenter.augment_image(image_norm, augmentation_type)
            
            # Save augmented images
            for i, aug_img in enumerate(augmented_images):
                if aug_img.max() <= 1:
                    aug_img = (aug_img * 255).astype(np.uint8)
                
                output_file = output_path / f"{image_id}_aug_{i}.png"
                cv2.imwrite(str(output_file), cv2.cvtColor(aug_img, cv2.COLOR_RGB2BGR))
                augmented_paths.append(str(output_file))
        
        return augmented_paths


def example_usage():
    """Example usage of batch processing."""
    print("Batch Processing - Example")
    print("Created by: RSK World (https://rskworld.in)")
    print("-" * 50)
    
    processor = BatchProcessor()
    
    # Get available images
    info = processor.loader.get_dataset_info()
    image_ids = [Path(img).stem for img in info['images'][:5]]
    
    if not image_ids:
        print("No images found. Please add images to the dataset first.")
        return
    
    # Define processing function
    def process_function(image, labels):
        # Extract features using available methods
        features = processor.advanced_processor.extract_all_features(image)
        # Get basic statistics
        stats = {
            'mean': float(np.mean(image)),
            'std': float(np.std(image)),
            'shape': image.shape
        }
        return {
            'features': {k: v for k, v in features.items() if not isinstance(v, str)},
            'statistics': stats
        }
    
    # Process batch
    results = processor.process_batch(
        image_ids=image_ids,
        processing_function=process_function,
        output_dir="output/batch_results"
    )
    
    print(f"\nProcessed {len(results)} images")
    print(f"Successful: {sum(1 for r in results if r['status'] == 'success')}")
    print(f"Failed: {sum(1 for r in results if r['status'] == 'failed')}")


if __name__ == "__main__":
    example_usage()

305 lines•10.8 KB
python
🚀 Support RSK World

Subscribe to our YouTube channel for latest tutorials & updates!



Click subscribe & support our work ❤️

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer