Segmentation with Geotiff image

19 views Asked by At

I want to make a k- means segmentation with python. My code works on jpg images, but when I try it with geotiff, it only makes the image black and white. How can ı solve this problem? Here is my code below;

import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from sklearn.cluster import KMeans

from PIL import Image
Image.MAX_IMAGE_PIXELS = None

from google.colab import drive
drive.mount('/content/drive')

# Dosya yolu, Google Drive'ınızda dosyanın bulunduğu yol

file_path = '/content/drive/MyDrive/Colab Notebooks/ortofoto.tif'

# TIFF dosyasını oku
image = mpimg.imread(file_path)
[text]([https://stackoverflow.com](https://stackoverflow.com))

# Dosyayı göster
plt.imshow(image)
plt.show()

X=image.reshape(-1, 4)
kmeans=KMeans(n_clusters=2, n_init=10).fit(X)

segmented_img=kmeans.cluster_centers_[kmeans.labels_]
segmented_img=segmented_img.reshape(image.shape)
plt.imshow(segmented_img/255)
0

There are 0 answers