27 lines
597 B
Python
27 lines
597 B
Python
from PIL import Image # type:ignore
|
|
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
|
|
# Membuka gambar
|
|
img = Image.open('cacao_dataset\monilia12 .jpg').convert('RGB')
|
|
|
|
# Ekstrak channel Red sebagai grayscale
|
|
r, g, b = img.split()
|
|
red_channel = np.array(r)
|
|
|
|
# Menampilkan hasil
|
|
fig, axes = plt.subplots(1, 2, figsize=(6, 3), facecolor='lightgray') # background abu-abu
|
|
|
|
# Citra Asli
|
|
axes[0].imshow(img)
|
|
axes[0].set_title('Citra Asli')
|
|
axes[0].axis('off')
|
|
|
|
# Channel Merah
|
|
axes[1].imshow(red_channel, cmap='gray')
|
|
axes[1].set_title('grayscale')
|
|
axes[1].axis('off')
|
|
|
|
plt.tight_layout()
|
|
plt.show()
|