multiple grouping octave and layers

Hey all, i want to ask how to grouping this data by octave (first column) and layer (second column), is there some way to do this? i thought it must be used groupcounts, i was tried, but still got an error. After grouping i must be sorted by the number. so i could know which minor of that group then proceed it first using kmeans(12) by at least 2 value every group. But if there is group that have less than 2, we skipped it.
1 1 159 92
1 1 111 43
1 1 111 64
1 1 119 56
1 1 131 113
1 2 192 121
1 2 192 104
1 2 203 63
2 2 147 84
2 2 150 73
2 2 166 31
2 2 167 70
2 2 171 70
2 2 181 32
2 2 183 80
2 2 185 85
3 1 200 18
3 1 134 63
3 2 110 31
groups would look like follows:
octave 3 and layer 2 = 1
octave 3 and layer 1 = 2
octave 1 and layer 2 = 3
octave 1 and layer 1 = 5
octave 2 and layer 2 = 8
result of kmeans must 12 point (i dont know how), so after using kmean at least like this below (number of group must be distributed)
octave 3 and layer 2 = 1
octave 3 and layer 1 = 2
octave 1 and layer 2 = 3
octave 1 and layer 1 = 3
octave 2 and layer 2 = 3

3 个评论

Okay, i want answer my own question, perhaps its help someone out there.
i = 12;
%for each keypoints octave
for octave = 1:size(keypointDescriptor, 1)
%for each keypoints layer
for kptLayer = 1:size(keypointDescriptor,2)
%checking in every pixel
[rowKpt colKpt] = find(keypointDescriptor{octave,kptLayer} == 1);
for keypoint = 1:size([rowKpt colKpt],1)
cont = cont+1;
%storing octave, layer, column and row each point
kMeansStack(cont) = struct('octave',octave,'kptLayer',kptLayer, ...
'kptX',colKpt(keypoint),'kptY',rowKpt(keypoint));
%take value from field
oct = extractfield(kMeansStack(cont),'octave');
lay = extractfield(kMeansStack(cont),'kptLayer');
%checking, is the value is exist
if octave == oct && kptLayer == lay
%if the value exist, it will count how many of them
iKpt(octave,kptLayer) = iKpt(octave,kptLayer)+1;
end
end
%storing the result of each octave and layer
Sorting(counter,1)=iKpt(octave,kptLayer); %result of counting
Sorting(counter,2)=octave; %which octave they are
Sorting(counter,3)=kptLayer; %which layer they are
counter=counter+1;
end
end
Sorting = sortrows(Sorting); %sorting row 1, from the minor one to the major
%because cant bring struct to if condition, so i make new variable to
%take value from field
indexStack(:,1) = extractfield(kMeansStack,'octave');
indexStack(:,2) = extractfield(kMeansStack,'kptLayer');
indexStack(:,3) = extractfield(kMeansStack,'kptX');
indexStack(:,4) = extractfield(kMeansStack,'kptY');
%here is checking of each octave and layer and change it
%the result must be 32 point for all octave and layer
for counter = 1:size(Sorting,1)
if Sorting(counter,1) < 3 %the main checking, checking is the value less than 3
numKpt = numKpt - Sorting(counter,1); %if less than 3, minus the numKpt
elseif Sorting(counter,1) >= 3 %if the point more than 3, it'll procced
j = numKpt / (size(Sorting,1)-(counter-1)); %count the rest point for each octave and layer
j = round(j);
if Sorting(counter,1) < j %to check if the numbers is fit
numKpt = numKpt - Sorting(counter,1);
else
Sorting(counter,1) = j;
numKpt = numKpt - Sorting(counter,1);
end
end
j = numKpt;
end
%exist
for cont = 1:size(indexStack,1)
for counter = 1:size(Sorting,1)
% %find(keypointDescriptor{octave,kptLayer} == 1)
if indexStack(cont,1) == Sorting(counter,2) && indexStack(cont,2) == Sorting(counter,3)
disp([num2str(indexStack(cont,1)) ' & ' num2str(indexStack(cont,2)) ' = ' ...
num2str(Sorting(counter,2)) ' & ' num2str(Sorting(counter,3))]);
X(cont,1) = indexStack(cont,3);
X(cont,2) = indexStack(cont,4);
if cont == size(indexStack,1) || ...
indexStack(cont,1) == Sorting(counter,2) && indexStack(cont+1,2) ~= Sorting(counter,3) || ...
indexStack(cont+1,1) ~= Sorting(counter,2) && indexStack(cont,2) == Sorting(counter,3)
[ ~, C] = kmeans(X,Sorting(counter,1));
%disp(['cont = ' num2str(cont) ' & size(idx) = ' num2str(size(idx,1))]);
%disp(['cont = ' num2str(counter) ' & size(idx) = ' num2str(size(Sorting,1))]);
%disp (C);
storeKmeans{:} = C;
%resKMeans{:} = [ C ];
end
end
end
end
Please give me some suggest if there's something wrong in my code, thanks
I didn't see where i was initialized. Anyway, we recommend against using i as an index or loop iterator/counter since it can also be used as the imaginary variable when using complex numbers. I have no idea what i and j even are so you should probably use a more descriptive variable name. Same comment for X, idx, and C -- use more descriptive names. It looks like C will get overwritten on each iteration and it doesn't look like you even do anything with it.
Ohh sorry, i was initialized 'i' in my code but didn't copy it in this code. I make 'i' as how many kpt i want in this case 'i = 12'. So 'i' minus by how many kpt in those octave and layer, as i said before each octave and layer at least have 2 kpt. If not, it will take from other octave and layer. At the end i get my kpt as much as i want. 'j' just giving hand to 'i', then but I can't find names that is suitable for the descriptive names. But i will try to find some.
I was try store it by using this code
storeKmeans{counter,1} = indexStack(cont,1);
storeKmeans{counter,2} = indexStack(cont,2);
storeKmeans{counter,3} = C(keypoint,1);
storeKmeans{counter,4} = C(keypoint,2);
It works, but could i make it to one line code?

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Octave 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by