Fahimeh Orvati Nia
commited on
Commit
·
10bba96
1
Parent(s):
2c0bae7
update
Browse files- app.py +2 -2
- sorghum_pipeline/pipeline.py +11 -9
- wrapper.py +6 -6
app.py
CHANGED
|
@@ -20,9 +20,9 @@ def process(image):
|
|
| 20 |
img_path = Path(tmpdir) / f"input.{ext}"
|
| 21 |
image.save(img_path)
|
| 22 |
outputs = run_pipeline_on_image(str(img_path), tmpdir, save_artifacts=True)
|
| 23 |
-
# Keep order consistent: return
|
| 24 |
order = [
|
| 25 |
-
'NDVI', 'ARI', 'GNDVI', 'LBP', 'HOG', 'Lacunarity', 'SizeAnalysis'
|
| 26 |
]
|
| 27 |
return [outputs[k] for k in order if k in outputs]
|
| 28 |
|
|
|
|
| 20 |
img_path = Path(tmpdir) / f"input.{ext}"
|
| 21 |
image.save(img_path)
|
| 22 |
outputs = run_pipeline_on_image(str(img_path), tmpdir, save_artifacts=True)
|
| 23 |
+
# Keep order consistent: return vegetation indices only for now
|
| 24 |
order = [
|
| 25 |
+
'NDVI', 'ARI', 'GNDVI' # , 'LBP', 'HOG', 'Lacunarity', 'SizeAnalysis'
|
| 26 |
]
|
| 27 |
return [outputs[k] for k in order if k in outputs]
|
| 28 |
|
sorghum_pipeline/pipeline.py
CHANGED
|
@@ -88,17 +88,18 @@ class SorghumPipeline:
|
|
| 88 |
return plants
|
| 89 |
|
| 90 |
def _extract_features(self, plants: Dict[str, Any]) -> Dict[str, Any]:
|
| 91 |
-
"""Extract
|
| 92 |
for key, pdata in plants.items():
|
| 93 |
-
# Texture: LBP, HOG, Lacunarity from pseudo-color
|
| 94 |
composite = pdata['composite']
|
| 95 |
mask = pdata.get('mask')
|
| 96 |
-
masked = self.mask_handler.apply_mask_to_image(composite, mask) if mask is not None else composite
|
| 97 |
-
gray = cv2.cvtColor(masked, cv2.COLOR_BGR2GRAY)
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
# Vegetation: NDVI, ARI, GNDVI
|
| 104 |
spectral = pdata.get('spectral_stack', {})
|
|
@@ -107,8 +108,9 @@ class SorghumPipeline:
|
|
| 107 |
else:
|
| 108 |
pdata['vegetation_indices'] = {}
|
| 109 |
|
| 110 |
-
# Morphology: PlantCV size analysis
|
| 111 |
-
pdata['morphology_features'] = self.morphology_extractor.extract_morphology_features(composite, mask)
|
|
|
|
| 112 |
|
| 113 |
return plants
|
| 114 |
|
|
|
|
| 88 |
return plants
|
| 89 |
|
| 90 |
def _extract_features(self, plants: Dict[str, Any]) -> Dict[str, Any]:
|
| 91 |
+
"""Extract features (NDVI only for now)."""
|
| 92 |
for key, pdata in plants.items():
|
|
|
|
| 93 |
composite = pdata['composite']
|
| 94 |
mask = pdata.get('mask')
|
|
|
|
|
|
|
| 95 |
|
| 96 |
+
# # Texture: LBP, HOG, Lacunarity from pseudo-color (COMMENTED OUT)
|
| 97 |
+
# masked = self.mask_handler.apply_mask_to_image(composite, mask) if mask is not None else composite
|
| 98 |
+
# gray = cv2.cvtColor(masked, cv2.COLOR_BGR2GRAY)
|
| 99 |
+
# feats = self.texture_extractor.extract_all_texture_features(gray)
|
| 100 |
+
# stats = self.texture_extractor.compute_texture_statistics(feats, mask)
|
| 101 |
+
# pdata['texture_features'] = {'color': {'features': feats, 'statistics': stats}}
|
| 102 |
+
pdata['texture_features'] = {}
|
| 103 |
|
| 104 |
# Vegetation: NDVI, ARI, GNDVI
|
| 105 |
spectral = pdata.get('spectral_stack', {})
|
|
|
|
| 108 |
else:
|
| 109 |
pdata['vegetation_indices'] = {}
|
| 110 |
|
| 111 |
+
# # Morphology: PlantCV size analysis (COMMENTED OUT)
|
| 112 |
+
# pdata['morphology_features'] = self.morphology_extractor.extract_morphology_features(composite, mask)
|
| 113 |
+
pdata['morphology_features'] = {}
|
| 114 |
|
| 115 |
return plants
|
| 116 |
|
wrapper.py
CHANGED
|
@@ -38,18 +38,18 @@ def run_pipeline_on_image(input_image_path: str, work_dir: str, save_artifacts:
|
|
| 38 |
# Collect outputs
|
| 39 |
outputs: Dict[str, str] = {}
|
| 40 |
|
| 41 |
-
# Return only
|
| 42 |
wanted = [
|
| 43 |
work / 'Vegetation_indices_images/ndvi.png',
|
| 44 |
work / 'Vegetation_indices_images/ari.png',
|
| 45 |
work / 'Vegetation_indices_images/gndvi.png',
|
| 46 |
-
work / 'texture_output/lbp.png',
|
| 47 |
-
work / 'texture_output/hog.png',
|
| 48 |
-
work / 'texture_output/lacunarity.png',
|
| 49 |
-
work / 'results/size.size_analysis.png',
|
| 50 |
]
|
| 51 |
labels = [
|
| 52 |
-
'NDVI', 'ARI', 'GNDVI', 'LBP', 'HOG', 'Lacunarity', 'SizeAnalysis'
|
| 53 |
]
|
| 54 |
for label, path in zip(labels, wanted):
|
| 55 |
if path.exists():
|
|
|
|
| 38 |
# Collect outputs
|
| 39 |
outputs: Dict[str, str] = {}
|
| 40 |
|
| 41 |
+
# Return only NDVI for now (others commented out for debugging)
|
| 42 |
wanted = [
|
| 43 |
work / 'Vegetation_indices_images/ndvi.png',
|
| 44 |
work / 'Vegetation_indices_images/ari.png',
|
| 45 |
work / 'Vegetation_indices_images/gndvi.png',
|
| 46 |
+
# work / 'texture_output/lbp.png',
|
| 47 |
+
# work / 'texture_output/hog.png',
|
| 48 |
+
# work / 'texture_output/lacunarity.png',
|
| 49 |
+
# work / 'results/size.size_analysis.png',
|
| 50 |
]
|
| 51 |
labels = [
|
| 52 |
+
'NDVI', 'ARI', 'GNDVI', # 'LBP', 'HOG', 'Lacunarity', 'SizeAnalysis'
|
| 53 |
]
|
| 54 |
for label, path in zip(labels, wanted):
|
| 55 |
if path.exists():
|