reshape and save data in a for loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a dataset of 100 rows and 3072 columns,and every single row represents an image.I want to divide every single image into 4 sub-images and get the mean of every color feature(rgb).The result should be 4,4,4(rgb) values,ie, for one image it should have 12 values.My code is,
function fr = features1(x)
[row col]=size(x);
f=[];
for i=1:row
r=x(i,(1:1024));
g=x(i,(1025:2048));
b=x(i,(2049:3072));
rre=reshape(r,32,32);
gre=reshape(g,32,32);
bre=reshape(b,32,32);
r1=mat2cell(rre,[32/2,32/2],[32/2,32/2]);
g1=mat2cell(gre,[32/2,32/2],[32/2,32/2]);
b1=mat2cell(bre,[32/2,32/2],[32/2,32/2]);
fr1=mean(r1{1}(:));
fr2=mean(r1{2}(:));
fr3=mean(r1{3}(:));
fr4=mean(r1{4}(:));
fg1=mean(g1{1}(:));
fg2=mean(g1{2}(:));
fg3=mean(g1{3}(:));
fg4=mean(g1{4}(:));
fb1=mean(b1{1}(:));
fb2=mean(b1{2}(:));
fb3=mean(b1{3}(:));
fb4=mean(b1{4}(:));
f(:,:,i)=[f,fr1,fg1,fb1;fr2,fg2,fb2;fr3,fg3,fb3;fr4,fg4,fb4]
end
end
It stores the values for only one image and rest is shown in command window but not stored in workspace. Moreover,I get these error messages:
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in features1 (line 26)
f(:,:,i)=[f,fr1,fg1,fb1;fr2,fg2,fb2;fr3,fg3,fb3;fr4,fg4,fb4]
Kindly help me in reshape and store all the values(1200) and also the values should be stored in the form red subimage1,green subimage1,blue subimage1 and in next line for subimage 2 and so on...
2 Kommentare
dpb
am 5 Okt. 2018
You've got LH variable in the RH expression...
f(:,:,i)=[f,fr1,fg1,fb1;fr2,fg2,fb2;fr3,fg3,fb3;fr4,fg4,fb4];
You can try
f(:,:,i)=[fr1,fg1,fb1;fr2,fg2,fb2;fr3,fg3,fb3;fr4,fg4,fb4];
and it possibly might work...
Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!