How to resolve this error ?
4 views (last 30 days)
Show older comments
z=imread('demo.jpg');
r=z(:,:,1);
g=z(:,:,2);
b=z(:,:,3);
CREATE A TRAINING SET
% Identify the location (row,column) of "training pixels" and assign them a "group number":
% You will need to identify at least 2 training pixels per group
%
tpix=[1309,640 ,1;... % Group 1: Yellow Bat
1218,755 ,1;...
1351,1409,2;... % Group 2: Grey Concrete
673 ,394 ,2;...
285 ,1762,3;... % Group 3: Red Tub
177 ,1542,3;...
538 ,1754,4;... % Group 4: Blue Tub
432 ,1811,4;...
1417,2010,5;... % Group 5: White Tub
163 ,1733,5;...
652 ,677 ,6;... % Group 6: Baby
864 ,1032,6;...
836 ,1882,7;... % Group 7: Dark Doormat
1063,1917,7];
row=tpix(:,1); % y-value
col=tpix(:,2); % x-value
group=tpix(:,3); % group number
ngroup=(group);
%
% From these pixels, make a training set consisting of each training pixel's band values
% "train" should have the same number of rows as the number of training pixels, and the
% same number of columns as number of bands (in this case 3, in Lansat case 7).
%
train=[];
% train=zeros(ngroup);
% train=ones(group); %(1,ngroup);
tic [class,err,misfit]=classify(AllPix,train,row); toc
When I run this code , error has occured as "TRAINING must have more observations than the number of groups"
0 Comments
Answers (1)
Adam Danz
on 14 Aug 2018
Read and understand how classify() works
doc classify
The 2nd input to classify() is 'training' which is a grouping variable and as the error tells you, you must have more observations (number of elements in 'training' vector) than groups (number of unique values in 'training').
Your code defines 'training' as
train = [];
which is empty.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!