Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sandeep-25 opened this issue Jul 13, 2019 · 3 comments
Open

Comments

@sandeep-25
Copy link

sandeep-25 commented Jul 13, 2019

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)

@YonghaoXu
Copy link
Owner

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

@sandeep-25
Copy link
Author

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.

@YonghaoXu
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants