Files
Code_Versions/workflow/feature_extractor_module.py
2026-02-16 02:11:24 +03:30

51 lines
1.5 KiB
Python

import pysera
import os
from workflow.module import Module
from workflow.io_port import InPort, OutPort, NIFTIImageType, CSVTableType
# Codes Go Below:
class FeatureExtractor(Module):
"""
Pure logical node for radiomics feature extraction.
No Dagster, no Engine, no state.
"""
def __init__(self):
super().__init__("FeatureExtractor")
self.addInPort(InPort("image", NIFTIImageType()))
self.addInPort(InPort("mask", NIFTIImageType()))
self.addOutPort(OutPort("features", CSVTableType(columns=["name", "value"])))
def run(self, context):
image = context.get_asset_value("FeatureExtractor.image")
mask = context.get_asset_value("FeatureExtractor.mask")
output_dir = "results"
os.makedirs(output_dir, exist_ok=True)
result = pysera.process_batch(
image_input=image,
mask_input=mask,
output_path=output_dir,
num_workers="auto",
enable_parallelism=True,
apply_preprocessing=True,
categories="all",
dimensions="1st,2_5d,3d",
feature_value_mode="REAL_VALUE",
extraction_mode="handcrafted_feature",
report="info",
)
df = result.get("features_extracted")
features = []
if df is not None:
for idx, row in df.iterrows():
features.append({"name": row[0], "value": row[1]})
return {"features": features}