|
|
from pathlib import Path |
|
|
from typing import Dict |
|
|
import shutil |
|
|
from PIL import Image |
|
|
import glob |
|
|
import os |
|
|
|
|
|
from sorghum_pipeline.pipeline import SorghumPipeline |
|
|
from sorghum_pipeline.config import Config, Paths |
|
|
|
|
|
|
|
|
def run_pipeline_on_image(input_image_path: str, work_dir: str, save_artifacts: bool = True) -> Dict[str, str]: |
|
|
""" |
|
|
Run sorghum pipeline on a single image (no instance segmentation). |
|
|
Returns dict[label -> image_path] for gallery display. |
|
|
""" |
|
|
|
|
|
work = Path(work_dir) |
|
|
work.mkdir(parents=True, exist_ok=True) |
|
|
|
|
|
|
|
|
input_path = Path(input_image_path) |
|
|
|
|
|
|
|
|
cfg = Config() |
|
|
cfg.paths = Paths( |
|
|
input_folder=str(work), |
|
|
output_folder=str(work), |
|
|
boundingbox_dir=str(work) |
|
|
) |
|
|
pipeline = SorghumPipeline(config=cfg) |
|
|
|
|
|
|
|
|
os.environ['MINIMAL_DEMO'] = '1' |
|
|
os.environ['FAST_OUTPUT'] = '1' |
|
|
results = pipeline.run(single_image_path=str(input_path)) |
|
|
|
|
|
|
|
|
outputs: Dict[str, str] = {} |
|
|
|
|
|
|
|
|
wanted = [ |
|
|
work / 'Vegetation_indices_images/ndvi.png', |
|
|
work / 'Vegetation_indices_images/ari.png', |
|
|
work / 'Vegetation_indices_images/gndvi.png', |
|
|
work / 'texture_output/lbp.png', |
|
|
work / 'texture_output/hog.png', |
|
|
work / 'texture_output/lacunarity.png', |
|
|
work / 'results/size.size_analysis.png', |
|
|
] |
|
|
labels = [ |
|
|
'NDVI', 'ARI', 'GNDVI', 'LBP', 'HOG', 'Lacunarity', 'SizeAnalysis' |
|
|
] |
|
|
for label, path in zip(labels, wanted): |
|
|
if path.exists(): |
|
|
outputs[label] = str(path) |
|
|
|
|
|
return outputs |
|
|
|