Adapt patch_extract in train_kmeans.py to work with images with alpha channel
Is your feature request related to a problem? Please describe.
Segmenting using unsupervised machine learning approach with the train_kmeans and kmeans_classifier, not compatible with images with alpha channel (img.shape[2]=4).
Describe the solution you'd like
At least my temporary work around solution was to add line of code that identifies that image contains the alpha channel and then slices it in patch_extract definition
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)
Describe alternatives you've considered Maybe include a note about it under the img definition in the function description?
Hi @jksshack thanks for opening this issue. I think the solution you propose should work nicely. Are you willing to make these changes in a Pull Request? If yes then we can add you as a contributor so you can open a PR branch (rather than a fork).
We just very recently updated pcv.predict_kmeans to accept an array directly rather than a filepath, which allows the alpha channel to be dropped with pcv.readimage(filename, mode="rgb"). So I think this means only learn.patch_extract needs updating.
@HaleySchuhl yeah, totally willing to!
@jksshack awesome! Thanks in advance. Malia has gone ahead and added you as a contributor. Please let me know if you have any questions.