How to filter image background

3 views (last 30 days)
Daniel
Daniel on 11 Aug 2014
I used this code
mu=1;
nsamples=1000000;
L=1;
l=1;
a1=1;
a2=1;
x01=-4+8*rand(nsamples,1);
y01=-4+8*rand(nsamples,1);
r01=sqrt(x01.^2+y01.^2);
rm1=mu*r01.*exp(-r01.^2/a1^2)+r01;
A1=atan2(y01,x01);
xm1=rm1.*cos(A1);
ym1=rm1.*sin(A1);
x02=-4+8*rand(nsamples,1);
y02=-4+8*rand(nsamples,1);
r02=sqrt(x02.^2+y02.^2);
rm2=mu*r02.*exp(-r02.^2/a2^2)+r02;
A2=atan2(y02,x02);
xm2=rm2.*cos(A2)+2;
ym2=rm2.*sin(A2);
A=reshape([xm1,ym1],[],2);
B=reshape([xm2,ym2],[],2);
A1=A(:,[1]);
A2=A(:,[2]);
B1=B(:,[1]);
B2=B(:,[2]);
x=vertcat(A1,B1);
y=vertcat(A2,B2);
values=hist3([x,y],[300,300]);
image=mat2gray(values);
image2=imcomplement(image);
image3=imrotate(image2,90);
x=linspace(-5,5,10000);
y=linspace(-5,5,10000);
figure
imshow(flipud(image3))
to generate this image:
What I am trying to do is eliminate the background noise. I want the background to be white, starting just outside of the circles I generated. I tried changing r01 and r02 but this made the image look artificial. I also tried changing the scale of mat2gray but couldn't come up with the right values.
I know that there are some redundancies in my code and it isn't very elegant---part of this reason is to make it more clear for application (ie differentiation of x01 and x02, use of L,l,a1,a2). This should be irrelevent for the image manipulation

Answers (0)

Community Treasure Hunt

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

Start Hunting!