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

39 ビュー (過去 30 日間)
Jonathan Medina
Jonathan Medina 2020 年 2 月 1 日
回答済み: Image Analyst 2020 年 2 月 1 日
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!

採用された回答

Image Analyst
Image Analyst 2020 年 2 月 1 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by