From cfd096c7a79f9241981dd19e4114dea61328c63e Mon Sep 17 00:00:00 2001 From: jksshack Date: Thu, 21 Aug 2025 09:36:58 -0400 Subject: [PATCH 1/2] Update train_kmeans.py add elif statement that addresses rgba images alpha channel is removed before applying gaussian blur --- plantcv/learn/train_kmeans.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plantcv/learn/train_kmeans.py b/plantcv/learn/train_kmeans.py index e5ee33e16..6463b5288 100644 --- a/plantcv/learn/train_kmeans.py +++ b/plantcv/learn/train_kmeans.py @@ -83,6 +83,9 @@ def patch_extract(img, patch_size=10, sigma=5, sampling=None, seed=1): img_blur = np.round(gaussian(img, sigma=sigma)*255).astype(np.uint16) elif len(img.shape) == 3 and img.shape[2] == 3: img_blur = np.round(gaussian(img, sigma=sigma, channel_axis=2)*255).astype(np.uint16) + elif len(img.shape) == 3 and img.shape[2] == 4: #rgb with alpha + img = img[:,:,:3] #removes alpha channel + img_blur = np.round(gaussian(img, sigma=sigma, channel_axis=2)*255).astype(np.uint16) # Extract patches patches = image.extract_patches_2d(img_blur, (patch_size, patch_size), From e962319b335121df3866f0eb98c7440af6070951 Mon Sep 17 00:00:00 2001 From: jksshack Date: Fri, 22 Aug 2025 13:17:41 -0400 Subject: [PATCH 2/2] Update train_kmeans.py --- plantcv/learn/train_kmeans.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plantcv/learn/train_kmeans.py b/plantcv/learn/train_kmeans.py index 6463b5288..b27ff4017 100644 --- a/plantcv/learn/train_kmeans.py +++ b/plantcv/learn/train_kmeans.py @@ -83,8 +83,8 @@ def patch_extract(img, patch_size=10, sigma=5, sampling=None, seed=1): img_blur = np.round(gaussian(img, sigma=sigma)*255).astype(np.uint16) elif len(img.shape) == 3 and img.shape[2] == 3: img_blur = np.round(gaussian(img, sigma=sigma, channel_axis=2)*255).astype(np.uint16) - elif len(img.shape) == 3 and img.shape[2] == 4: #rgb with alpha - img = img[:,:,:3] #removes alpha channel + elif len(img.shape) == 3 and img.shape[2] == 4: # rgb with alpha + img = img[:, :, :3] # removes alpha channel img_blur = np.round(gaussian(img, sigma=sigma, channel_axis=2)*255).astype(np.uint16) # Extract patches