フィルターのクリア

How do I change a 512*512 image code to any size code?

4 ビュー (過去 30 日間)
Diptayan Dasgupta
Diptayan Dasgupta 2021 年 5 月 12 日
コメント済み: Diptayan Dasgupta 2021 年 5 月 13 日
I wrote the code to find the lowpass filter of grayscale image of size 512*512 pixels. How to change it to any other size?
A=imread('lena.png'); % read 512512 8bit image
A=double(A);
A=A/255;
SP=fftshift(fft2(fftshift(A)));
D=abs(SP);
D=D(129:384,129:384);
figure;imshow(A);
title('Original image')
figure;imshow(30.*mat2gray(D)); % spectrum
title('Original spectrum')
c=1:512;
r=1:512;
[C, R]=meshgrid(c, r);
CI=((R-257).^2+(C-257).^2);
filter=zeros(512,512);
% produce a high-pass filter
for a=1:512;
for b=1:512;
if CI(a,b)>=20^2; %filter diameter
filter(a,b)=0;
else
filter(a,b)=1;
end
end
end
G=abs(filter.*SP);
G=G(129:384,129:384);
figure;imshow(30.*mat2gray(G));
title('Low-pass spectrum')
SPF=SP.*filter;
E=abs(fftshift(ifft2(fftshift(SPF))));
figure;imshow(mat2gray(E));
title('Low-pass image')
  1 件のコメント
Walter Roberson
Walter Roberson 2021 年 5 月 12 日
You did not post the code, so we do not know what implementation you used.

サインインしてコメントする。

採用された回答

DGM
DGM 2021 年 5 月 13 日
This should be a start
% this presumes the image is uint8, so be careful
% if you have IPT, you can use im2double() instead
A=double(A);
A=A/255;
% ...
% these numbers in the following rows are functions
% of the presumed image geometry and/or the size of the filter
% rewrite them in general terms; for example:
% [h w nc] = size(A);
% padsize = floor([h w]/4); % assuming the same ratio
% D = D((1+padsize):(h-padsize),(1+padsize):(w-padsize));
D=D(129:384,129:384);
% ...
c=1:512; % 1:w
r=1:512; % 1:h
% ...
CI=((R-257).^2+(C-257).^2); % 257 is ((h or w)/2 + 1)
filter=zeros(512,512); % filter=zeros(h,w);
for a=1:512 % 1:h
for b=1:512 % 1:w
% maybe filter diameter should be defined earlier as a parameter
if CI(a,b)>=20^2
% ...
end
end
end
% ...
G=G(129:384,129:384); % etc
  1 件のコメント
Diptayan Dasgupta
Diptayan Dasgupta 2021 年 5 月 13 日
Thank you so much for this.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRead, Write, and Modify Image についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by