필터 지우기
필터 지우기

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

조회 수: 2 (최근 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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Read, 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