quickly finding value of matrix
2 views (last 30 days)
Show older comments
Tran Tuan Anh
on 7 Jun 2014
Answered: Image Analyst
on 7 Jun 2014
Dear everyone
I have the problem when I compute in a matrix. This problem is about the speed of computation.
I have a matrix of binary image (f), I find conected component by bwlabel in matlab. [L num]=bwlabel(f);
after that base on some property I found a vector p that include some value of L that I need to remove. this is my code and explanation
function [f,L] = clear_nontext(f,L,nontext)
% p is a vector include a lot of value we need to remove
p=find(nontext(:)~=0);
% example p= [1 2 9 10 100...] that mean we need to find in L matrix where get the value =1,2,9,10,100..] and remove it
[a b]=size(L);
g=zeros(a,b);
for u=1:length(p)
for i=1:a
for j=1:b
if L(i,j)==p(u)
g(i,j)=1;
%L(i,j)=500000;
f(i,j)=0;
end
end
end
end
end
When I use this way, program run but it is so slow, because with one value of p we need to check all value in matrix f (or L) again. So I need another way to run it faster. Could you help me?
Thank you so much
0 Comments
Accepted Answer
Image Analyst
on 7 Jun 2014
Tran: The usual way to do it is to use ismember(). You can look in my Image Segmentation Tutorial to see how I filter away blobs, based on some criteria such as area, using ismember(). http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
0 Comments
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!