File size: 3,846 Bytes
ee9e0d6 a42cf37 ee9e0d6 a42cf37 0e577bf ee9e0d6 a42cf37 ee9e0d6 a42cf37 0e577bf a42cf37 ee9e0d6 a42cf37 ee9e0d6 0e577bf ee9e0d6 0e577bf a42cf37 ee9e0d6 0e577bf ee9e0d6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | """
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"
}
|