Question

In: Electrical Engineering

I blurred a grayscale image using a 5x5 average filter and then I am supposed to...

I blurred a grayscale image using a 5x5 average filter and then I am supposed to deblur using an Inverse filter using Constrained Division. Is there a better way to do this?

The error that pops up is this:

 Error using  ./ 
 Complex integer arithmetic is not supported.
 Error in test2 (line 12)
 fbw = fftshift(fft2(blur))./bw;

When I blur the image using a butterworth filter it works just fine yet when I blur using the average filter my code won't work. Below is my attempt:

 clear
 I = imread('buffalo.png');
 H = fspecial('average',[5 5]) ;
 blurred=imfilter(I,H);
 blur=im2uint8(mat2gray((blurred)));
 imshow(blur)
 d = 0.01;           
 bw = blurred;        
 bw(find(bw<d)) = 1; 
 fbw = fftshift(fft2(blur))./bw; 
 ba = abs(ifft2(fbw)); 
 unb01 = im2uint8(mat2gray(ba));

Solutions

Expert Solution

im=imread('Sharon2.jpg');

y=rgb2gray(im);

z=imresize(y,[512 512]);

x=imrotate(z,-270);

figure,

imshow(x);

% 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')

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


Related Solutions

I am in a class where I am supposed to be Minister of Foreign Affair representing...
I am in a class where I am supposed to be Minister of Foreign Affair representing India. I was invited to the G20 meeting to discuss and present negotiations with other countries of G20. The agenda will have two major items: international health cooperation and international economic cooperation. What negotiations could I do for India with other countries to improve the current situation and look for financial stability?
I am in a class where I am supposed to be a Civil Society Organization Representative...
I am in a class where I am supposed to be a Civil Society Organization Representative (CSO) representing India. I was invited to the G20 meeting to discuss and present negotiations with other countries of G20.The agenda will have two major items: international health cooperation and international economic cooperation. What negotiations could I do for India with other countries to improve the current situation and look for financial stability?
Scenario: I am creating a course for inclusion into an established nursing curriculum. I am supposed...
Scenario: I am creating a course for inclusion into an established nursing curriculum. I am supposed to describe the program level of the course am proposing. What do they mean by program level? This is a hypothetical community college with a two year nursing program.
What I am trying to do is to design a Butterworth Bandpass filter using Matlab, High...
What I am trying to do is to design a Butterworth Bandpass filter using Matlab, High frequency must equal to 16 Hz and lower frequency must be 10Hz (passBand). and the input signal must be a white noise signal. here is my code : mu=0; sigma=2; X= sigma*randn(500,1)+mu; %Generating White Noise signal Fs=500;%Sampling Frequency Fh= 16; Fl=10; order=6; [b,a]=butter(order,[Fh Fl]/(Fs/2),'bandpass');%Butterworth BandPass filter XX=filtfilt(b,a,X);%filter the signal both forward and backword in time Actually, I am not sure about Fs value that...
I thought for this type of question I am supposed to make a chart with the...
I thought for this type of question I am supposed to make a chart with the inventory, purchases, sales, etc., but instead, these questions are throwing me off for the little understanding I have on this new topic... Kayla Company uses the perpetual inventory system and the LIFO method. The following information is available for the month of June: June 1 Beginning inventory 200 units @ $5 12 Purchase on account 400 units @ $6 15 Sales on account 440...
I am not able to upload a image of the question or in tables as it...
I am not able to upload a image of the question or in tables as it is formated. Any suggestions how i can do this? Thank you Penny’s Rent A Car Penny’s Rent a Car offers three rental plans as shown in Table 1. Please note that the fixed cost is provided in terms of months. Later, you will be asked to construct a cost table in terms of annual cost. Table 1. Rental plan characteristics Plan Fixed Monthly Payment...
I was wondering if I was doing a conversion right. I am supposed to take aqueous...
I was wondering if I was doing a conversion right. I am supposed to take aqueous HNO3 with a density of 1.42 g/mL and a mass percent of solution of 70% and convert that into molarity. Would the correct conversion be to take 70 g of HNO3 over 100 g of H2O multiplied by 1 mol HNO3 over 63.01 g HNO3 (the molar mass) and then multiply that by 1 g H2O over 0.001 L of H2O to get the...
C programming language. **I am aware that I am only supposed to ask one question so...
C programming language. **I am aware that I am only supposed to ask one question so if you cant do all of this could you please do part 2? thank you! This lab, along with your TA, will help you navigate through applying iterative statements in C. Once again we will take a modular approach to designing solutions to the problem below. As part of the lab you will need to decide which C selection structure and iterative structure is...
C programming language. **I am aware that I am only supposed to ask one question so...
C programming language. **I am aware that I am only supposed to ask one question so if you cant do all of this could you please do part 3? thank you! This lab, along with your TA, will help you navigate through applying iterative statements in C. Once again we will take a modular approach to designing solutions to the problem below. As part of the lab you will need to decide which C selection structure and iterative structure is...
I am supposed to be looking at the OMIM online database under hypercholesterolemia, and I cannot...
I am supposed to be looking at the OMIM online database under hypercholesterolemia, and I cannot find the answer to this question on their webpage. What is the relationship between the LDL receptor and hepatitis C virus?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT