Fahimeh Orvati Nia
commited on
Commit
·
f2055ee
1
Parent(s):
08b06f5
update
Browse files
sorghum_pipeline/data/preprocessor.py
CHANGED
|
@@ -26,7 +26,11 @@ class ImagePreprocessor:
|
|
| 26 |
"""Process 4-band to composite + spectral."""
|
| 27 |
d = pil_img.size[0] // 2
|
| 28 |
boxes = [(j, i, j + d, i + d) for i, j in product(range(0, pil_img.height, d), range(0, pil_img.width, d))]
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# Split into 4 bands and squeeze the extra dimension
|
| 32 |
green, red, red_edge, nir = [band.squeeze(-1) for band in np.split(stack, 4, axis=-1)]
|
|
|
|
| 26 |
"""Process 4-band to composite + spectral."""
|
| 27 |
d = pil_img.size[0] // 2
|
| 28 |
boxes = [(j, i, j + d, i + d) for i, j in product(range(0, pil_img.height, d), range(0, pil_img.width, d))]
|
| 29 |
+
# Convert each quadrant crop to grayscale to ensure 2D per band
|
| 30 |
+
stack = np.stack([
|
| 31 |
+
np.array(pil_img.crop(box).convert('L'), dtype=float)
|
| 32 |
+
for box in boxes
|
| 33 |
+
], axis=-1)
|
| 34 |
|
| 35 |
# Split into 4 bands and squeeze the extra dimension
|
| 36 |
green, red, red_edge, nir = [band.squeeze(-1) for band in np.split(stack, 4, axis=-1)]
|