SSUN icon indicating copy to clipboard operation
SSUN copied to clipboard

ValueError: cannot reshape array of size 435 into shape (145,145,3)

Open sandeep-25 opened this issue 4 years ago • 3 comments

labels=sio.loadmat("Indian_pines_gt.mat")['indian_pines_gt'] palette=np.array([[255,0,0],[0,255,0],[0,0,255],[255,255,0],[0,255,255],[255,0,255],[176,48,96],[46,139,87],[160,32,240],[255,127,80],[127,255,212],[218,112,214],[160,82,45],[127,255,0],[216,191,216],[238,0,0]]) palette=palette*1.0/255 X_result=np.zeros((labels.shape[0],3)) num_class=labels.max() or i in range(0,num_class): X_result[np.where(labels==i),0]=palette[i,0] X_result[np.where(labels==i),1]=palette[i,1] X_result[np.where(labels==i),2]=palette[i,2] X_result=np.reshape(X_result,(145,145,3))

I am getting the following error, ValueError: cannot reshape array of size 435 into shape (145,145,3)

sandeep-25 avatar Jul 13 '19 00:07 sandeep-25

Hi, I think the labels here should be reshaped into a vector form (e.g., labels = labels.reshape(145*145, 1)).

YonghaoXu avatar Jul 13 '19 02:07 YonghaoXu

X_result=np.zeros((labels.shape[0]*labels.shape[1],3)) num_class=labels.max() X_result = np.zeros((labels.shape[0]*labels.shape[1],3)) for i in range(0,num_class): X_result[np.where(labels==i),0] = palette[i,0] X_result[np.where(labels==i),1] = palette[i,1] X_result[np.where(labels==i),2] = palette[i,2] I repeated the experiment as per your comment but I am not getting the plot of the image.

sandeep-25 avatar Jul 13 '19 10:07 sandeep-25

Hi, you can use the matplotlib package to save the classification map. import matplotlib.pyplot as plt ... plt.imsave('clsmap.png',X_result)

YonghaoXu avatar Jul 15 '19 00:07 YonghaoXu