For Loop issue in code

1 view (last 30 days)
rizwan
rizwan on 22 Mar 2015
Commented: rizwan on 22 Mar 2015
Can anyone please guide in this scenario.. I have
out = [a,histc(idx(:),a)]; % out variable having cluster number and cluster size
[a,ix]= max(out(:,2)); %getting the max value in a and its index in ix variable
[row , col] = find(idx ==ix);%using find func in checking where in idx the ix exists and storing the row col index in row and col
mx_row = max(row); %getting max row index
mx_col = max(col);%getting max col index
for i = 1 : mx_row %for loop till max row index
for j = 1 : mx_col %for loop till max col index
cp = I(row(i),col(j));% getting the row and col indexes and accessing the element from I and store it in cp
end
end
There is error for loops it is not storing the values at corresponding locations! Please help
  2 Comments
Image Analyst
Image Analyst on 22 Mar 2015
I can't tell from this snippet. What is the badly-named "a" and idx? And what's the point of computing cp? You're not even indexing it, so it's a scalar (a single number not an array) - and you're just getting it and throwing it away.
What is the overall goal of this code? To find the max intensity in an image???
rizwan
rizwan on 22 Mar 2015
Let me explain with details.... Step 1> I have an image on which i have applied k mean clustering to get clusters, for this what i did is
index_string = int2str(k);
Image_Path = strcat('D:\MS\Research\Classification Model\Research Implementation\EnhancedImage\ROI',index_string,'.jpeg');
I1 = imread(Image_Path);
I=double(I1);
figure
subplot(1,3,1)
imshow(I1)
subplot(1,3,2)
% [idx, C] = kmeans(I(:),4, 'distance','sqEuclidean', 'EmptyAction','singleton', 'replicates',1,'Display','iter');
[idx,C]= kmeans_fast_Color(I,4,'Display', 'iter');
Above code is working fine and doing well
Step two> In this step what i want is to calculate the cluster size and select the big cluster from all four clusters. What i did for this is
a = unique(idx);
out = [a,histc(idx(:),a)];
[a,ix]= max(out(:,2));
It works fine...Up till now i have the max cluster size and its number stored in a and idx respectively....
Step 3> In this step what i want to do is to use the max cluster number and iterate over the idx cluster array to find the locations of the cluster number and store them in a variable. Now i have the locations of the cluster numbers, using these locations i want to extract the pixel numbers from the original Image I and stored in some variable for further use...What i did for this is
[row , col] = find(idx ==ix);
mx_row = max(row);
mx_col = max(col);
for i =1 : max(row)
for j= 1: max(col)
cp = I(i,j);
end
end
cp is the variable in which i want to store the pixels values...but there is a bug which i m not able to find for storing pixel values in cp!!!!!!!!!!
I hope you have now a clear idea of my problem...
Thanks in ADVANCE For assistance!!!
Regards

Sign in to comment.

Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!