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