Spaces:
Sleeping

minyuuu / src /core /preprocessing_factory.py
Péter Gergely Dániel
[Upd] Main interface multi prprocessing input support
0e577bf
Raw History Blame Contribute Delete
3.85 kB
"""
Factory function for creating preprocessing modules from type names and parameters.
"""
from typing import Dict, Any, Optional
from .base_processor import PreprocessingModule
from preprocessing import (
IdentityPreprocessor,
DownscaleModule,
GrayscaleConverter,
ChannelSplitter,
GaussianBlurModule,
EdgeDetectorModule,
SkinColorSegmenterModule,
DownscaleWithInterpolationPreprocessor,
EdgeSmoothingModule,
HoleClosingModule,
ObjectSeparatorModule,
ThresholdFillModule,
)
def create_preprocessing_module(step_type: str, parameters: Dict[str, Any] = None) -> Optional[PreprocessingModule]:
"""
Create a preprocessing module from type name and parameters.
Args:
step_type: Type name of the preprocessing module
parameters: Dictionary of parameters for the module
Returns:
PreprocessingModule instance or None if type not found
"""
if parameters is None:
parameters = {}
if step_type == "None":
return IdentityPreprocessor()
elif step_type == "Downscale (640px)":
return DownscaleModule(max_dimension_length=640)
elif step_type == "Downscale (480px)":
return DownscaleModule(max_dimension_length=480)
elif step_type == "Downscale (300px)":
return DownscaleModule(max_dimension_length=300)
elif step_type == "Downscale with interpolation (640px)":
return DownscaleWithInterpolationPreprocessor(max_size=640)
elif step_type == "Downscale with interpolation (480px)":
return DownscaleWithInterpolationPreprocessor(max_size=480)
elif step_type == "Grayscale":
return GrayscaleConverter()
elif step_type == "Split":
return ChannelSplitter()
elif step_type == "Blur":
return GaussianBlurModule()
elif step_type == "Edge detection":
return EdgeDetectorModule(
lower_thresh=int(parameters.get("lower_thresh", 0)),
upper_thresh=int(parameters.get("upper_thresh", 40))
)
elif step_type == "Downscale":
return DownscaleModule(
max_dimension_length=parameters.get("max_dimension_length", 640)
)
elif step_type == "ChannelSplitter":
return ChannelSplitter()
elif step_type == "GaussianBlur":
return GaussianBlurModule()
elif step_type == "EdgeSmoothing":
return EdgeSmoothingModule()
elif step_type == "HoleClosing":
return HoleClosingModule()
elif step_type == "ObjectSeparator":
return ObjectSeparatorModule()
elif step_type == "ThresholdFill":
return ThresholdFillModule()
elif step_type == "SkinColorSegmenter":
return SkinColorSegmenterModule(
parameters.get("model_path", "models/skin_segmentation/model1")
)
else:
print(f"Warning: Unknown preprocessing type: {step_type}")
return None
def get_preprocessing_type_names() -> Dict[str, str]:
"""
Get list of available preprocessing type names.
Returns:
Dictionary mapping internal names to display names (same in this case)
"""
return {
"None": "None",
"Downscale (640px)": "Downscale (640px)",
"Downscale (480px)": "Downscale (480px)",
"Downscale (300px)": "Downscale (300px)",
"Downscale with interpolation (640px)": "Downscale with interpolation (640px)",
"Downscale with interpolation (480px)": "Downscale with interpolation (480px)",
"Grayscale": "Grayscale",
"Split": "Split",
"Blur": "Blur",
"Edge detection": "Edge detection",
"SkinColorSegmenter": "SkinColorSegmenter",
"EdgeSmoothing": "EdgeSmoothing",
"HoleClosing": "HoleClosing",
"ObjectSeparator": "ObjectSeparator",
"ThresholdFill": "ThresholdFill"
}