Image rectangle using matrix - antialiasing

5 views (last 30 days)
Hi, I'm trying to write a script that draws a rectangle from an array. It remains to solve the problem mainly on the edge antialiasing. Can someone help me? thanks
function linea
Nx = 64;
Ny = 64;
x0 = 32;
y0 = 32;
l = 30;
h = 5;
for theta = 0:0.5:360.5
im = ones(Nx,Ny);
theta = theta * pi / 180;
for i = -l/2:l/2
for j = -h/2:h/2
x = x0 + i * cos(theta) + j * sin(theta);
y = y0 - i * sin(theta) + j * cos(theta);
im(round(x),round(y)) = 0;
end
end
imagesc(im,[0 1]);
axis image
colormap gray
drawnow
end
end

Accepted Answer

Image Analyst
Image Analyst on 18 Nov 2013
You can blur im with conv2() to smooth out edges. But a bigger problem is the way you send 0's to your output image. Doing that will give you "holes" where no pixel got set. You need to invert that and scan your output array and figure out what 4 pixels in the input it should come from. If you do that you'll not only eliminate holes, but also have smooth edges because you'll be doing bilinear interpolation.
  1 Comment
Giuseppe
Giuseppe on 20 Nov 2013
Thanks for the reply ... Could you help me to implemtare the construction of the rectangle?

Sign in to comment.

More Answers (0)

Categories

Find more on Image Processing Toolbox 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!