By using reshape () in Matlab getting this error .

img=imread('flair.jpg');
gaborArray = gaborFilterBank(5,6,39,39);
featureVector = gaborFeatures(img,gaborArray,1,1);
img_size=size(img(:));
fv=reshape(featureVector, size(img_size),30);
out=kmeans(fv,5); %k-means where k=5
%Apply histogram of texton map within each super pixel
res=hist(out,5);
disp(res)
Error: Error using reshape Size arguments must be integer scalars. Error in texton (line 8) fv=reshape(featureVector, size(img_size),30);

 採用された回答

Stephen23
Stephen23 2018 年 4 月 24 日
編集済み: Stephen23 2018 年 4 月 24 日

0 投票

This
img_size=size(img(:));
will return a 1x2 row vector equivalent to this:
[numel(img),1]
Then you get the size of the 1x2 vector img_size using
size(img_size)
which will therefore always return the vector [1,2], which is not a scalar, and is thus an invalid input to reshape. Note that the syntax size(X) will always return an 1xN vector, where N>=2.
It is not clear what you are trying to do.

4 件のコメント

Javaid Iqbal
Javaid Iqbal 2018 年 4 月 24 日
Sir, basically I want to reshape on featurVector the given image size and also multiply with 30 because I'm applying gaborFeature. When I put scaler values in place of size(img_size) then no error.
Javaid Iqbal
Javaid Iqbal 2018 年 4 月 24 日

Please see attachment and I just apply the given code on this but facing this error. Please help me how this will be resolve. Thanks

   % code
img=imread('flair.jpg');
gaborArray = gaborFilterBank(5,6,39,39);            
featureVector = gaborFeatures(img,gaborArray,1,1);   
img_size=size(img(:));
fv=reshape(featureVector, size(img_size),30);  
out=kmeans(fv,5);               %k-means where k=5 
%Apply histogram of texton map within  each super pixel 
res=hist(out,5);
disp(res)
Stephen23
Stephen23 2018 年 4 月 24 日
編集済み: Stephen23 2018 年 4 月 24 日

Put the new size into one vector:

[size(img_size),30]

it works for me:

fv = reshape(featureVector,[size(img),30]);

As its help shows, reshape does not support both multiple inputs and a non-scalar input at the same time: either all separate inputs need to be scalar (one may be empty), or use one non-scalar input.

Javaid Iqbal
Javaid Iqbal 2018 年 4 月 25 日
Thanks sir for helping me

サインインしてコメントする。

その他の回答 (0 件)

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by