11-05 20:19
Notice
Recent Posts
Recent Comments
관리 메뉴

Scientific Computing & Data Science

[Image Processing] Gaussian Blurring 본문

Scientific Computing/Image Processing

[Image Processing] Gaussian Blurring

cinema4dr12 2014. 6. 6. 18:27

MATLAB CODE: "Gaussian.m"

function Gaussian %% read an image img = imread('./res/test_02.jpg'); img = rgb2gray(img); subplot(2,1,1); imshow(img); mask = [1/16 1/8 1/16 ; 1/8 1/4 1/8 ; 1/16 1/8 1/16]; [rSize, cSize] = size(mask); [nrow, ncol] = size(img); img = cast(img, 'double'); newImg = zeros(nrow,ncol); % Corners subMask = mask(2:3,2:3); i = 1; j = 1; subMat = img(i:i+1,j:j+1); newImg(i,j) = sum(sum(subMask.*subMat)); subMask = mask(1:2,1:2); i = nrow; j = ncol; subMat = img(i-1:i,j-1:j); newImg(i,j) = sum(sum(subMask.*subMat)); % Edges subMask = mask(2:3,1:3); i = 1; for(j = 2:ncol-1) subMat = img(i:i+1,j-1:j+1); newImg(i,j) = sum(sum(subMask.*subMat)); end subMask = mask(1:2,1:3); i = nrow; for(j = 2:ncol-1) subMat = img(i-1:i,j-1:j+1); newImg(i,j) = sum(sum(subMask.*subMat)); end subMask = mask(1:3,2:3); j = 1; for(i = 2:nrow-1) subMat = img(i-1:i+1,j:j+1); newImg(i,j) = sum(sum(subMask.*subMat)); end subMask = mask(1:3,1:2); j = ncol; for(i = 2:nrow-1) subMat = img(i-1:i+1,j-1:j); newImg(i,j) = sum(sum(subMask.*subMat)); end % Inner for(i = 0.5*(rSize+1) : nrow - 0.5*(rSize+1)) for(j = 0.5*(cSize+1) : ncol - 0.5*(cSize+1)) subMat = img(i-1:i+1,j-1:j+1); newImg(i,j) = sum(sum(subMat.*mask)); end end subplot(2,1,2); newImg = cast(newImg, 'uint8'); imshow(newImg); end


테스트용 이미지(test_02.jpg)


결과 (위: 원본 이미지, 아래: 블러 처리된 이미지)

Comments