Pixel Extraction From Using Cluster

4 次查看(过去 30 天)
rizwan
rizwan 2015-3-25
Hi Experts
Let me explain my problem with details....I have an image from which i need to find the big cluster for this i m using k means and it works fine, now i want to extract the pixels of this big cluster from from the image provided, i m not able to find the pixels of big cluster and then store in a variable ...Please help i have written complete code below with appropriate explanation....
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

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by