Digital Image Processing Using MATLAB Digital Image Processing
Digital Image Processing Using MATLAB®
Digital Image Processing Using MATLAB® Chapter 4 Frequency Domain Processing
Digital Image Processing Using MATLAB® Q: Why does it look like (d)?
Digital Image Processing Using MATLAB® 함수 fftshift • 함수 fftshift: 변환의 원점을 주파수 직각사 각형의 중앙으로 옮겨줌. Fc = fftshift(F) – 예: a = [1 2; 3 4] fftshift(a) = [4 3; 2 1] • 변환 후 fftshift를 적용한 결과 == 영상을 (-1)x+y 로 곱한 후 변환한 결과 • [(-1)x+y f(x, y)] == fftshift(fft 2(f)) != fft 2(fftshift(f))
Digital Image Processing Using MATLAB® Fourier Spectrum의 Log 변환 >> S 2 = log(1 + abs(Fc)); >> imshow(S 2, [ ]) 그림 4. 3(d). 디테일이 살아남. • 중앙으로 옮긴 작업을 되돌리기: 함수 ifftshift F = ifftshift(Fc) – § 4. 4에서 이용
Digital Image Processing Using MATLAB® 그림 4. 3(d)
Digital Image Processing Using MATLAB® 푸리에 변환 예 (사진 출처: Sonka’s)
Digital Image Processing Using MATLAB®
Digital Image Processing Using MATLAB®
Digital Image Processing Using MATLAB®
Digital Image Processing Using MATLAB® 스펙트럼 영상 size : 필터 size = ?
Digital Image Processing Using MATLAB® N savings ratio
Digital Image Processing Using MATLAB®
Digital Image Processing Using MATLAB® • Assume: f(x, y) ~ A B, h(x, y) ~ C D • f와 h를 0으로 패딩 두 개의 P Q 함수 • wraparound 오차를 피하기 위해서는: P A+C-1 Q B+D-1 • If 둘 다 M N, P 2 M – 1 Q 2 N – 1
Digital Image Processing Using MATLAB® Preparation ischar: tf = ischar(A) returns logical true (1) if A is a character array and logical false (0) otherwise. Example: Given the following cell array, C{1, 1} = magic(3); C{1, 2} = 'John Doe'; C{1, 3} = 2 + 4 i C = [3 x 3 double] 'John Doe' [2. 0000+ 4. 0000 i] for k = 1: 3 x(k) = ischar(C{1, k}); end x x= 0 1 0
Digital Image Processing Using MATLAB® 연습 If >> CD = [3 4] then >> ischar(CD) ans = 0
Digital Image Processing Using MATLAB® nextpow 2: p = nextpow 2(A) 1. if A ~ scalar (incl. complex): returns the smallest p that satisfies 2^p abs(A) 예: For any integer n ~ [513, 1024], nextpow 2(n) returns 10 2. If A ~ non-scalar: returns the smallest p that satisfies 2^p length(A). 예: For a 1 30 A ( length(A) = 30), nextpow 2(A) = 5
Digital Image Processing Using MATLAB® nextpow 2()의 연습 >> A = [11: 20] A= 11 12 13 14 15 16 17 18 19 20 >> p = nextpow 2(A) % ∵ length(A)는 10 p= 4
Digital Image Processing Using MATLAB® function PQ = paddedsize(AB, CD, PARAM) %PADDEDSIZE Computes padded sizes useful for FFT-based filtering. % PQ = PADDEDSIZE(AB), where AB is a two-element size vector, % computes the two-element size vector PQ = 2*AB. % % PQ = PADDEDSIZE(AB, 'PWR 2') computes the vector PQ such that % PQ(1) = PQ(2) = 2^nextpow 2(2*m), where m is MAX(AB) % % PQ = PADDEDSIZW(AB, CD), where AB and CD are two-element size % vectors, computes the two-element size vector PQ. The elements % of PQ are the smallest even integers greater than or equal to % AB + CD - 1. % % PQ = PADDEDSIZE(AB, CD, 'PWR 2') computes the vector PQ such that % PQ(1) = PQ(2) = 2^nextpow 2(2*m), where m is MAX([AB CD]).
Digital Image Processing Using MATLAB® if nargin == 1 PQ = 2*AB; % M, N ~ 짝수 elseif nargin == 2 & ~ischar(CD) PQ = AB + CD - 1; % p. 116 PQ = 2 * ceil(PQ / 2); elseif nargin == 2 m = max(AB); % Maximum dimension. % Find power-of-2 at least twice m. P = 2^nextpow 2(2*m); PQ = [P, P];
Digital Image Processing Using MATLAB® elseif nargin == 3 m = max([AB CD]); % Maximum dimension. P = 2^nextpow 2(2*m); PQ = [P, P]; else error('Wrong number of inputs. ') end
Digital Image Processing Using MATLAB®
Digital Image Processing Using MATLAB® Filtering w/o Padding >> [M, N] = size(f); >> F = fft 2(f); >> sig =10; >> H = lpfilter('gaussian', M, N, sig); % 필터 생성 >> G = H. *F; >> g = real(ifft 2(G)); >> imshow(g, [ ])
Digital Image Processing Using MATLAB® >> imshow(g, [ ])
Digital Image Processing Using MATLAB® >> imshow(fftshift(abs(F)))
Digital Image Processing Using MATLAB® >> imshow(fftshift(abs(H))) >> imshow(fftshift(abs(G)))
Digital Image Processing Using MATLAB®
Digital Image Processing Using MATLAB® 패딩을 사용한 필터링 >> PQ = paddedsize(f)); % case I % → 2 → wraparound 오차 x(; 짝수) >> Fp = fft 2(f, PQ(1), PQ(2)); % fft w/ pad. >> Hp = lpfilter('gaussian', PQ(1), PQ(2), 2*sig); % 필터 크기가 패딩이 없을 때의 두 배 2 * sig 사용 >> Gp = Hp. *Fp; >> gp = real(ifft 2(Gp)); >> gpc = gp(1: size(f, 1), 1: size(f, 2)); >> imshow(gpc, [ ])
Digital Image Processing Using MATLAB® Fp and Hp: 512 >> imshow(fftshift(log(1+abs(·))), [ ])
Digital Image Processing Using MATLAB® Gp
Digital Image Processing Using MATLAB® imshow(gp) imshow(gp, []) 40 ~ 60 230 10 ~ 20 • class(gp) = double • max(gp(: )) = 230; min(gp(: )) = -9. 9476 e-014
Digital Image Processing Using MATLAB® imshow(gpc) imshow(gpc, [])
Digital Image Processing Using MATLAB®
Digital Image Processing Using MATLAB® 공간 필터링에 의한 방법 >> h = fspecial('gaussian', 15, 7); >> gs = imfilter(f, h); % 디폴트 0으로 패딩(§ 3. 4. 1) >> imshow(gs), figure, imshow(gs, [])
Digital Image Processing Using MATLAB® Basic Steps for Filtering in the Frequency Domain
Digital Image Processing Using MATLAB® function g = dftfilt(f, H) %DFTFILT Performs frequency domain filtering. % G = DFTFILT(F, H) filters F in the frequency domain using the % filter transfer function H. The output, G, is the filtered % image, which has the same size as F. DFTFILT automatically pads % F to be the same size as H. Function PADDEDSIZE can be used % to determine an appropriate size for H. % DFTFILT assumes that F is real and that H is a real, uncentered, % circuarly-symmetric filter function.
Digital Image Processing Using MATLAB® % 1. Obtain the FFT of the padded input. % cf. paddedsize F = fft 2(f, size(H, 1), size(H, 2)); % 2. Perform filtering. g = real(ifft 2(H. *F)); % 3. Crop to original size. g = g(1: size(f, 1), 1: size(f, 2));
- Slides: 77