Basic Anti-aliasing Filter (Intro to Signals & Systems)

39 views (last 30 days)
I am trying to create a function
zaa = antialias(z);
which inputs a hi-res image z and outputs high-res anti-aliased image zaa. The system needs to compute each point of zaa[x,y]:
Annotation 2020-02-01 151650.png.
The given "high-res" image z is:
z = round(exp(-1/w.^2*((y.'-30).^2+(x-40).^2)));
I am confused on how to implement the Zaa equation into my function. Here's what I have for my function thus far:
function zaa = antialias(z)
zaa = zeros(size(z,1), size(z,2));
for nn = 1:size(z,1) % grabs the number of rows
for mm = 1:size(z,2) % grabs number of columns
if nn > 1 && nn < size(z,1) && mm > 1 && mm < size(z,2)
%zaa(nn,mm) = 1/4 * (z(nn-1,mm)+z(nn+1,mm)+z(nn,mm-1)+z(nn,mm+1));
%zaa(nn,mm) = 1/4 * z(nn-1,nn+1,mm-1,mm+1);
%zaa(nn,mm) = 1/4 * z(nn,mm);
%xx = [nn-1 nn+1 nn nn];
%yy = [mm mm mm-1 mm+1];
%zaa(nn,mm) = 1/4 * z(xx,yy);
end
end
end
end
The commented out section includes my 4 attempts at coding in the difference equation. I'm sure you can tell I am a novice with arrays and MATLAB. I am hoping for some guidence on how to write the function appropriately. Any help would be appreciated.
Thanks!

Accepted Answer

Image Analyst
Image Analyst on 1 Feb 2020
Try this:
function zaa = antialias(z)
kernel = 1 + [0,1,0; 1,0,1; 0,1,0]/4;
zaa = conv2(z, kernel, 'same');
Note: Because your kernel is not normalized, and sums to 2, your output image zaa will be, on average, twice as bright as z. To avoid that, do this
function zaa = antialias(z)
kernel = 1 + [0,1,0; 1,0,1; 0,1,0]/4;
kernel = kernel / sum(kernel(:));
zaa = conv2(z, kernel, 'same');
Then the output image will have the same average brightness as the input image.

More Answers (0)

Categories

Find more on Convert Image Type 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!