Finding Values From Arrays
1 次查看(过去 30 天)
显示 更早的评论
Hi Experts,
I have the following lines of code
I =
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/148698/image.png)
I = imread(abc.jpg)
[idx,C] = adaptcluster_kmeans(I);
idx =
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/148699/image.png)
a = unique(idx); //Unique values from idx e.g 1 2 3
out = [a,histc(idx(:),a)];//Frequency of unique value
e.g
1 18221
2 28383
3 18080
[a,ix]= max(out(:,2)); //max unique value and its index
a = 28383 ix = 2
Now what i want to do is to use this 'ix' and extract the corresponding pixel values and store them in an excel file....
e.g ix = 2 in this case then i want to extract
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/148700/image.png)
Can any help how i can achieve this
Regards & Thanks
0 个评论
采纳的回答
Mahdiyar
2015-4-4
Hi rizwan
You can simply use the "find" command line.
[row column] = find(idx == ix)
Regards
3 个评论
Mahdiyar
2015-4-5
Hi
As I understood you just want to store the found pixel in the new variable in the exactly the same position (Row and Column). If so, you may follow the code below.
New_Variable = zeros(n, m); % n and m are the row and column of the matrix in which the original image is saved
for i=1:lenght(Row)
New_Variable(Row(i), Col(i)) = Original_Image(Row(i), Col(i));
end
I think now it works. Regards,
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Feature Detection and Extraction 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!