Need help troubleshooting this coding

3 ビュー (過去 30 日間)
Michael
Michael 2013 年 10 月 19 日
コメント済み: Michael 2013 年 10 月 19 日
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 件のコメント
Michael
Michael 2013 年 10 月 19 日
Also, here is 'periodicpattern.jpg'. This image is the output I'm trying to get to appear in Figure 3, and on both the left-hand side and the right-hand side of Figure 4. The only difference between the images in Figure 4 is that the right-hand side should just be me reading in 'periodicpattern.tif' and displaying it. Whereas, the left-hand side is supposed to prove that I can take the original image, 'Proj2.tif', extract that mesh periodic pattern out of it, and display that pattern which should equal the 'periodicpattern.tif' file.
Note 'periodicpattern.tif' = 'periodicpattern.jpg'. These files are the same images, just different formats.
Same holds true with 'Proj2.tif'. 'Proj2.tif' = 'Proj2.jpg'
Thanks!
Michael
Michael 2013 年 10 月 19 日
編集済み: Michael 2013 年 10 月 19 日
So far, this seems like the closest result I can get, but it still doesn't look anywhere close to the image in 'periodicPattern.jpg'
imshow(A - log(abs(FilterImage2)),[]);
At least it's a darker image, but I don't know what function I should be performing to get the image to display right in both Figure 3 and on the left-hand side of Figure 4.
Do you think using meshgrid() in some form or fashion might work?

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeComputer Vision with Simulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by