Need help troubleshooting this coding
Show older comments
if true
% code
end
% Jon Michael Gresham
% ECE4367 Image Processing
% Undergraduate, Sr.
% 10/17/2013
%
% Project 2: Implement a method in Matlab for extracting
% the periodic pattern that is vaguely visible in the image
% 'Proj.tif'
% Clear the workspace
clc
% Read the image 'Proj2.tif'
% Figure 1 displays the Original Image.
Proj2Image = 'Proj2.tif';
[img,map] = imread(Proj2Image);
figure
imshow(img,map);
title('Original Image');
% Store the original image as an array.
img = img(:,:,1);
% Perform the Fast Fourier Transform (FFT) on the Image
imgfft = fft2(img);
% Next, I create a Butterworth Low-Pass Filter.
% Note: c is a constant
% X is the size of the dimension of array X
% Y is the size of the dimension of array Y
c = 2;
X = size(imgfft, 1);
Y = size(imgfft, 2);
% A returns an array of ones in X and Y.
A = ones(X,Y);
% 7 unique pixels are used in each array.
XX = [204 182 191 196 214 219 228];
YY = [273 275 267 282 264 279 271];
% L = Max Number of Pixels = 255
L = 255;
for i=1:length(L)
for x = 1:X
for y = 1:Y
%Compute the distance between the points.
Lxy = sqrt((x-XX(i))^2 + (y-YY(i))^2);
A(x,y) = A(x,y) + 1/(1+(Lxy/L(i)^2))^(2*c);
end
end;
end;
% Next, I apply the Butterworth filter by shifting
% the FFT of the image, and multiplying it by A.
FilterImage = fftshift(imgfft).*A;
figure
imshow(abs(FilterImage),[]);
title('Image After Shifting by FFT and Multiplying By A');
% Here, I shift back and perform the Inverse FFT
FilterImage2 = ifft2(fftshift(FilterImage));
figure
imshow(abs(FilterImage2),[]);
title('Shifting Back and Performing Inverse FFT');
% Then I resize and display the 'periodicpattern.tif' image
% And compare it to the output Image named 'FilterImage2'.
[img,map] = imread('periodicpattern.tif');
figure('Name','Periodic Pattern Comparison');
subplot(1,2,1), imshow(abs(FilterImage2),[]);
title('Periodic Pattern of Image');
subplot(1,2,2), imshow(img,map);
title('periodicpattern.tif');
So I've been debugging this program for a few days now. I still can't seem to get to correct output that I'm looking for though. The program currently displays 4 figures, which is exactly what I want. However, the output images in Figure 3 and Figure 4 need to be modified a little bit.
What I'm trying to do is take the original image 'Proj2.tif', extract the mesh periodic cross pattern out of it, and display that mesh pattern in Figure 3. I also want that image to appear in the left-hand side of Figure 4 so I can prove that extracting the periodic pattern of the image can be done by applying the FFT, Shifting It, Multiplying it by an array of ones, Shifting it back, and performing the inverse FFT.
I provided the .jpg format of the original image to you guys in this forum since the forum board won't accept .tif files for some reason.
Obviously, the method I'm using currently to try to get this result isn't working. I thought about using a log function in Line 66 and Line 74 to fix this, but that strategy isn't working either.
By the way, this is Line 66 and Line 74 respectively below:
imshow(abs(FilterImage2),[]); %Line66
subplot(1,2,1), imshow(abs(FilterImage2),[]); %Line77
Any feedback or help on this problem would be greatly appreciated.
2 Comments
Michael
on 19 Oct 2013
Answers (0)
Categories
Find more on Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!