ASKER
ASKER
from skimage.color import rgb2gray
X_gray = np.zeros(X_train.shape[128:128:1])
for i in range(X_train.shape[0]):
X_gray[i] = rgb2gray(i)
#X_gray[i] = cv2.cvtColor(X_train[i], cv2.COLOR_BGR2GRAY)
ASKER
i = 10
image = images_all[i]
label = label_data[i]
print(f'Label \n Label name: {label}')
plt.imshow(image);
from skimage.color import rgb2gray
# calculating the illuminance apparantly gives us the gray scale of the image
im_gray = rgb2gray(image)
# the module to visualize the image
# we decide the display size of the visualisation
plt.figure(figsize = (10,4))
# In the current figure, create and return an Axes, at position index of a (virtual) grid of nrows by ncols axes. Indexes go from 1 to nrows * ncols, incrementing in row-major order.
# If nrows, ncols and index are all less than 10, they can also be given as a single, concatenated, three-digit number.
plt.subplot(1,2,1)
#displays the image on the axis
plt.imshow(image)
#turns off the axis and the labels
plt.axis('off')
plt.title("the original image")
#if the value of parameters in the arguements are less than 10 then they can be written in the sequence
plt.subplot(122)
#for gray scale image a corresponding parameter for Cmap is passed
plt.imshow(im_gray,cmap = 'gray')
plt.axis('off')
# the display of the grayScale image
plt.title("grayScaleImage")
# tight_layout automatically adjusts subplot params so that the subplot(s) fits in to the figure area.
plt.tight_layout()
plt.show()
ASKER
ASKER
ASKER
Open in new window
https://stackoverflow.com/questions/12201577/how-can-i-convert-an-rgb-image-into-grayscale-in-python