How can I blur an image pixel by pixel, given an input image of 512 by 512 pixel
1 view (last 30 days)
Show older comments
A patch of the image size 16 by 16 is blurred first leaving the others unchanged, then another step of blurring 32 by 32 leaving the others unchanged. I have started using the Gaussian filter but I don't know how to blur by each pixel on the same image
im=imread('Sharon2.jpg');
y=rgb2gray(im);
z=imresize(y,[512 512]);
x=imrotate(z,-270);
figure,
imshow(x);
0 Comments
Answers (1)
Image Analyst
on 5 Apr 2015
Not exactly sure what you want to do but look into using fspecial() and either conv2() or imfilter().
9 Comments
Image Analyst
on 6 Apr 2015
Did you try putting my first code I gave you into the second code like I suggested?
% Define blur kernel
hsize = 17;
sigma = 5; % Whatever
kernel = fspecial('gaussian', hsize, sigma)
% Read in sample image.
grayImage = imread('cameraman.tif'); % Sample image.
[rows, columns, numberOfColorChannels] = size(grayImage)
w = floor(hsize/2);
for col = w+1 : columns - w
for row = w+1 : rows - w
% code to filter one pixel at location (row, col)
% Get a window around the target pixel that we
% will consider when blurring.
row1 = row - w;
row2 = row1 + hsize - 1;
col1 = col - w;
col2 = col1 + hsize - 1;
subImage = double(grayImage(row1:row2, col1:col2));
% Blur the pixel at row, column.
tempImage = subImage .* kernel;
newPixelValue = uint8(sum(tempImage(:)));
% Put blurred value back into original image
grayImage(row, col) = newPixelValue;
end
end
imshow(grayImage, []);
title('Blurred Image', 'FontSize', 30);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
Now, what are you going to do to make this assignment your own?
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!