How can I blur an image pixel by pixel, given an input image of 512 by 512 pixel

1 view (last 30 days)
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);

Answers (1)

Image Analyst
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
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?
Oluwamayowa Sanni
Oluwamayowa Sanni on 6 Apr 2015
Edited: Image Analyst on 6 Apr 2015
Yes I did..
grayImage = imread('Sharon2.jpg'); % Sample image.
z=imresize(grayImage,[512 512]);
x=imrotate(z,-270);
y=rgb2gray(x);
figure,
imshow(y);
% Define blur kernel
hsize = 17;
sigma = 5; % Whatever
kernel = fspecial('gaussian', hsize, sigma);
% Read in sample image.
grayImage = imread('Sharon2.jpg'); % Sample image.
z=imresize(grayImage,[512 512]);
x=imrotate(z,-270);
y=rgb2gray(x);
figure,
imshow(y);
% Get a window around the target pixel that we
% will consider when blurring.
row1 = 100 - floor(hsize/2);
row2 = row1 + hsize - 1;
col1 = 150 - floor(hsize/2);
col2 = col1 + hsize - 1;
subImage = double(grayImage(row1:row2, col1:col2));
% Blur the pixel at row 100, column 150.
tempImage = subImage .* kernel;
newPixelValue = uint8(sum(tempImage(:)));
% Put blurred value back into original image
grayImage(100, 150) = newPixelValue;
figure,
imshow(tempImage);
% for col = 1 : columns
% for row = 1 : rows
% % code to filter one pixel at location (row, col)
% end
% end

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!