Question

In: Computer Science

Matlab question: 1. Implement image filtering in frequency domain on the "testtpattern512.tif" image. You will design...

Matlab question:

1. Implement image filtering in frequency domain on the "testtpattern512.tif" image. You will design the filter, and filter the image in the frequency domain, then use inverse DFT to display the filtered image in the spatial domain. Assume zero padding for filtering process.

a- Design a rectangular ideal low pass filter with a cutoff frequency of (Uo, Vo), filtering the image so that the vertical lines are blurred together, horizontal lines are basically intact and the letters are still readable. Uo, and Vo represent the cutoff frequencies in two dimensions. You may need to try different Uo, Vo, to find the best settings.

b- Design a Gaussian low pass filter with cutoff frequency of radius (sigma) Do, so that in the filtered image the large letter ‘a’ is barely readable, the other letters are not. You may need to try different Uo, to find the best settings. Please compute mean square error (MSE) between the original image and resulted blurred image for five Uo settings, sort them and explain why MSE decreases along with the increase of Do.

c- Design a Fifth-order Butterworth high pass filter, use circular cutoff, Do, so that only edges of shapes are clearly shown. You may need to try different Uo, to find the best settings. Please compute mean square error (MSE) between the original image and resulted image for five Uo settings, sort them and explain why MSE increases along with the increase of Do.

Solutions

Expert Solution

% Demo to filter an image, with periodic ripple, in the Fourier domain.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 14;

% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'cameraman.tif';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
[rows columns numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
grayImage = rgb2gray(grayImage);
end
subplot(2, 3, 1);
imshow(grayImage, [0 255]);
set(gcf, 'Name', ['Results for ' fullFileName]);
title('Original Image', 'FontSize', fontSize);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.

% Add big ripples to it.
rowVector = (1 : rows)';
period = 10; % 20 rows
amplitude = 0.5; % Magnitude of the ripples.
offset = 1 - amplitude; % How much the cosine is raised above 0.
cosVector = amplitude * (1 + cos(2 * pi * rowVector / period))/2 + offset;
ripplesImage = repmat(cosVector, [1, columns]);
subplot(2, 3, 2);
minValue = min(min(ripplesImage))
maxValue = max(max(ripplesImage))
imshow(ripplesImage, [0 maxValue]);
axis on;
title('Ripples to multiply the image by', 'FontSize', fontSize);
% Multiply the ripples by the image to get an image with periodic "noise" in it.
grayImage = ripplesImage .* double(grayImage);
minValue = min(min(grayImage))
maxValue = max(max(grayImage))
subplot(2, 3, 3);
imshow(grayImage, [0 255]);
axis on;
title('Original Image with Periodic "Noise" ripples', 'FontSize', fontSize);

% Compute the 2D fft.
frequencyImage = fftshift(fft2(grayImage));
% Take log magnitude so we can see it better in the display.
amplitudeImage = log(abs(frequencyImage));
minValue = min(min(amplitudeImage))
maxValue = max(max(amplitudeImage))
subplot(2, 3, 4);
imshow(amplitudeImage, []);
caption = sprintf('Notice the two spikes\nperpendicular to the periodic frequency');
title(caption, 'FontSize', fontSize);
axis on;
% zoom(10)

% Find the location of the big spikes.
amplitudeThreshold = 10.9;
brightSpikes = amplitudeImage > amplitudeThreshold; % Binary image.
subplot(2, 3, 5);
imshow(brightSpikes);
axis on;
title('Bright Spikes', 'FontSize', fontSize);
% Let user see the image.
promptMessage = sprintf('The image below shows the bright spikes.\nNow we will exclude the central spike.');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
return;
end
% Exclude the central DC spike. Everything from row 115 to 143.
brightSpikes(115:143, :) = 0;
imshow(brightSpikes);
title('Bright spikes other than central spike', 'FontSize', fontSize);

promptMessage = sprintf('Now we will use these bright spikes to filter (mask) the spectrum.');
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
return;
end
% Filter/mask the spectrum.
frequencyImage(brightSpikes) = 0;
% Take log magnitude so we can see it better in the display.
amplitudeImage2 = log(abs(frequencyImage));
minValue = min(min(amplitudeImage2))
maxValue = max(max(amplitudeImage2))
subplot(2, 3, 5);
imshow(amplitudeImage2, [minValue maxValue]);
axis on;
title('Spikes zeroed out', 'FontSize', fontSize);
% zoom(10)

filteredImage = ifft2(fftshift(frequencyImage));
amplitudeImage3 = abs(filteredImage);
minValue = min(min(amplitudeImage3))
maxValue = max(max(amplitudeImage3))
subplot(2, 3, 6);
imshow(amplitudeImage3, [minValue maxValue]);
title('Filtered Image', 'FontSize', fontSize);
% set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.
% %


Related Solutions

1.) Explain the difference between a time domain signal and a frequency domain signal. 2.) When...
1.) Explain the difference between a time domain signal and a frequency domain signal. 2.) When would you select the frequency domain signal over the time domain signal.
1- Write a Matlab program to perform image resizing, image rotation to 90 degrees, conversion to...
1- Write a Matlab program to perform image resizing, image rotation to 90 degrees, conversion to binary and gray scale, Image segmentation and extraction, draw and find the region of interest with a circle, Plot bounding box, Region extraction and histogram. 2- Write a MATLAB program to Design a GUI calculator which is as shown in below figure 1. Add tool bar options to the GUI calculator and Highlight specific codes written in program and signify the steps followed.
Using Matlab 1. Create a color image of size 200 × 200. The image should have...
Using Matlab 1. Create a color image of size 200 × 200. The image should have a blue background. 2. Create 100 yellow regions within the image that have a variable size. More specifically, their width should be an odd number and vary between 3 and 7 and their height should also be an odd number and vary between 3 and 7. For example, you may get rectangular regions of size 3 × 3, 3 × 5, 5 × 3,...
Implement the steffenson method in matlab. The code must be in MATLAB DOnt answer if you...
Implement the steffenson method in matlab. The code must be in MATLAB DOnt answer if you cannot give correct MATLAB
Design E shape microstrip patch array antenna in ansys for a frequency and write the matlab...
Design E shape microstrip patch array antenna in ansys for a frequency and write the matlab code for it. i need this all with matlab code.if you are able to do then try or else leave it for other.ONLY WANT MATLAB CODE
Design Rectangular array antenna in HFSS software or 5Ghz frequency and MATLAB CODE FOR IT. need...
Design Rectangular array antenna in HFSS software or 5Ghz frequency and MATLAB CODE FOR IT. need all the output waveform regarding that Design microstrip array antenna in HFSS software and MATLAB CODE FOR IT. IF YOU KNOW THEN ONLY DO OR ELSE LEAVE FOR OTHER ANTENNA ,ELECTRICAL ENGINEERING
C++ Question The aim of this assignment is to design and implement a computerized “Library Management...
C++ Question The aim of this assignment is to design and implement a computerized “Library Management System”. The system will be used in the back-office to manage the books in the library catalog and to keep track of the various users (borrowers) of the library. The system provides the following key functionalities: Books are characterized by a call number, a title, and a flag that indicates whether the book is currently ‘on-shelf’ (in the library) or ‘on-loan’. -Adding and removing...
MATLAB. Design your own low-cut shelving filter which can cut the low frequency of given music...
MATLAB. Design your own low-cut shelving filter which can cut the low frequency of given music signal. Include magnitude and phase plot of your filter.
1) Design and implement a method to double all elements of an array. Important: You don’t...
1) Design and implement a method to double all elements of an array. Important: You don’t need to test test method in main(). You don’t need to initialize the array. pubilc static void doubleElements(int [] arr) { } 2) Start with the code below and complete the getInt method. The method should prompt the user to enter an integer. Scan the input the user types. If the input is not an int, throw an IOException; otherwise, return the int. In...
Question: In MATLAB, Implement a hybrid clustering algorithm which combines hierarchical clustering and k-means clustering. The...
Question: In MATLAB, Implement a hybrid clustering algorithm which combines hierarchical clustering and k-means clustering. The hybrid algorithm will use hierarchical clustering to produce stable clusters and k-means clustering will initialize seeds based on the centroids of the produced stable clusters (instead of randomly initialized seeds) Background Information: Both hierarchal clustering and k-means clustering group similar data objects into clusters. However, the two algorithms have their pros and cons. For example, hierarchical clustering produces stable clusters while k-means clustering generates...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT