QUick and DIrty Domain Adaptation (QuDiDA)

0.0.4 · active · verified Wed Apr 15

QuDiDA is a micro library designed for quick and naive pixel-level image domain adaptation. It leverages scikit-learn transformers for its operations and is primarily intended as an image augmentation technique. The current version is 0.0.4, with releases being infrequent; the last update was in August 2021, suggesting a low-maintenance but functional status.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `qudida.DomainAdapter` to perform pixel-level domain adaptation. It initializes the adapter with a `scikit-learn` transformer (e.g., `PCA`) and a reference (target) image. It then applies the adaptation to a source image, returning the adapted image. Ensure `opencv-python-headless` and `scikit-learn` are installed as dependencies. The example includes creating dummy images to ensure the code is runnable without external files.

import cv2
from sklearn.decomposition import PCA
from qudida import DomainAdapter
import os

# Create dummy image files for demonstration if they don't exist
# In a real scenario, these would be your source and target images.
if not os.path.exists('source.png'):
    dummy_img = (255 * (0.5 + 0.5 * (1 + 0.2 * (0.5 - 0.5 * (0.5 * (2 * 0.5 - 1) + 0.5)) + 0.5))) * 255
    cv2.imwrite('source.png', dummy_img.astype('uint8'))
if not os.path.exists('target.png'):
    dummy_img_target = (255 * (0.5 + 0.5 * (1 + 0.2 * (0.5 - 0.5 * (0.5 * (2 * 0.5 - 1) + 0.5)) + 0.5))) * 255
    cv2.imwrite('target.png', dummy_img_target.astype('uint8'))

# Initialize the DomainAdapter with a scikit-learn transformer and a reference (target) image
# For simplicity, using a dummy image if actual images are not present
ref_img_path = 'target.png'
source_img_path = 'source.png'

# Ensure dummy images exist for the quickstart to run
if not os.path.exists(ref_img_path) or not os.path.exists(source_img_path):
    # If dummy images were not created above (e.g., due to a previous run or error),
    # create them directly here for robustness.
    import numpy as np
    dummy_source = np.full((100, 100, 3), [100, 50, 200], dtype=np.uint8) # BGR blue-ish
    dummy_target = np.full((100, 100, 3), [50, 200, 100], dtype=np.uint8) # BGR green-ish
    cv2.imwrite(source_img_path, dummy_source)
    cv2.imwrite(ref_img_path, dummy_target)

adapter = DomainAdapter(transformer=PCA(n_components=3), ref_img=cv2.imread(ref_img_path))

# Load the source image
source = cv2.imread(source_img_path)

# Apply domain adaptation
result = adapter(source)

# Save the result (optional, for verification)
# cv2.imwrite('result_adapted.png', result)

print("Domain adaptation applied successfully. Result image shape:", result.shape)
# Clean up dummy files
os.remove(source_img_path)
os.remove(ref_img_path)

view raw JSON →