How to correctly generate a structure?

Dear all,
I encountered an issue regarding collecting information in a structure.
I work on a 200 images database, which I split into 3 sets of pictures (imdb(i).normal, imdb(i).atipic and imdb(i).mela), on which I apply a kmeans segmentation on 4 clusters. After the segmentation I wish to retain in 3 structures the value for intensity, the minimum position and the minimum value for the clusters of each picture, so I should have another 3 structures each with 200 values.
for i = 1:80
M = false(size(imdb(i).normal(:,:,1)));
M = true(size(imdb(i).normal,1), size(imdb(i).normal,2));
[L(i).normal,C_RGB(i).normal] = kmeansfcn(imdb(i).normal,K,M);
hold on;
% figure('Position',[168,182,1625,744])
% subplot(2,1,1),imshow(imdb(i).normal)
% title('Imagine originala')
% pause(1);
%afisarea legendei
leg = {}; hold on
for j=1:K
Col(i).normal = (C_RGB(i).normal(j,:)./255);
leg(j,:)={['Cluster ',num2str(j)]};
%Color={'reg','green','blue'};
%plot(1,1,'LineWidth',12,'Color',Col)
end
% legend(leg,'FontSize',12);hold off
% L(i).normal=L(i).normal(1:4:end, 1:4:end,:); % subsampling-iau din 4 in 4 pixeli=> micsorez aria de 4 ori
% subplot(2,1,2),imshow(L(i).normal,[])
% title('Segmentare pe clustere')
% pause(1);
intens(i).normal=(mean(C_RGB(i).normal'))';
[valmin(i).normal, posmin(i).normal]=min(intens(1).normal);
end
The thing is, after the first loop is done I have saved in intens(i).normal 80 values which is correct, but valmin(i).normal and posmin(i).normal are showing the same values from top to bottom. My guess is that there is something wrong with the writing or with C_RGB(i).normal which represents the cluster centroids
for i = 81:160
M = false(size(imdb(i).atipic(:,:,1)));
M = true(size(imdb(i).atipic,1), size(imdb(i).atipic,2));
[L,C_RGB] = kmeansfcn(imdb(i).atipic,K,M);
% hold on;
% figure('Position',[168,182,1625,744])
% subplot(2,1,1),imshow(imdb(i).atipic)
% title('Imagine originala')
% pause(1);
%
% % afisarea legendei
leg = {}; hold on
for j=1:K
Col(i).atipic = (C_RGB(i).atipic(j,:)./255);
leg(j,:)={['Cluster ',num2str(j)]};
% plot(1,1,'LineWidth',12,'Color',Col)
end
legend(leg,'FontSize',12);hold off
% L(i).atipic=L(i).atipic(1:4:end, 1:4:end,:); % subsampling-iau din 4 in 4 pixeli=> micsorez aria de 4 ori
% subplot(2,1,2),imshow(L(i).atipic,[])
% title('Segmentare pe clustere')
% pause(1);
intens(i).atipic=(mean(C_RGB(i).atipic'))';
[valmin(i).atipic,posmin(i).atipic]=min(intens(1).atipic);
end
for i = 161:200
M = false(size(imdb(i).mela(:,:,1)));
M = true(size(imdb(i).mela,1), size(imdb(i).mela,2));
[L,C_RGB] = kmeansfcn(imdb(i).mela,K,M);
% hold on;
% figure('Position',[168,182,1625,744])
% subplot(2,1,1),imshow(imdb(i).mela)
% title('Imagine originala')
% pause(1);
% afisarea legendei
leg = {}; hold on
for j=1:K
Col(j).nume = (C_RGB(j.n(j,:)./255);
leg(j,:)={['Cluster ',num2str(j)]};
%plot(1,1,'LineWidth',12,'Color',Col)
end
%legend(leg,'FontSize',12);hold off
%L(i).mela=L(i).mela(1:4:end, 1:4:end,:); % subsampling-iau din 4 in 4 pixeli=> micsorez aria de 4 ori
% subplot(2,1,2),imagesc(L(i).mela,[])
% title('Segmentare pe clustere')
% pause(1);
intens(i).mela=(mean(C_RGB(i).mela'))';
[valmin(i).mela,posmin(i).mela]=min(intens(i).mela);
end
After I try to run any of these two loops I get an error on this line Col(i).mela=(C_RGB(i).mela(j,:)./255); Index exceeds matrix dimensions. I also lose the previous data I had in the structures with the same name.
Can you please help me out?
Thanks in advance
Best regards

Answers (0)

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Asked:

on 17 Jun 2019

Community Treasure Hunt

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

Start Hunting!