File size: 1,800 Bytes
61b3c2b dd1d7f5 61b3c2b dd1d7f5 61b3c2b 7613956 61b3c2b dd1d7f5 61b3c2b dd1d7f5 61b3c2b dd1d7f5 7613956 61b3c2b dd1d7f5 61b3c2b |
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 |
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)
# Use input path directly (already in work_dir from app.py)
input_path = Path(input_image_path)
# Build in-memory config pointing input/output to the working directory
cfg = Config()
cfg.paths = Paths(
input_folder=str(work),
output_folder=str(work),
boundingbox_dir=str(work)
)
pipeline = SorghumPipeline(config=cfg)
# Run the pipeline (single image minimal demo)
os.environ['MINIMAL_DEMO'] = '1'
os.environ['FAST_OUTPUT'] = '1'
results = pipeline.run(single_image_path=str(input_path))
# Collect outputs
outputs: Dict[str, str] = {}
# Return only the requested 7 images with fixed keys
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
|