the effect of PSF in x-ray image
3 ビュー (過去 30 日間)
古いコメントを表示
hi am trying to find the effect of the PSF on x-ray image , i generate the psf using a for loop then use convolution with the image , after that taking fft for both PSF and image seeing the spectrum ... but after conv function and ifft it give black image why?
clc
clear all
close all
im=imread('xray2.jpg');
[m,n]=size(im);
PSF=zeros(n,m);
Y=size(PSF,1);
X=size(PSF,2);
s_x=1;
s_y=5;
for x=1:X
for y=1:Y
PSF(y,x) = exp(-((x-X).^2/(2*s_x^2) + (y-Y).^2)/(2*s_y^2));
end
end
%Display PSF
figure(1)
imshow(PSF)
title('PSF')
colormap gray
figure(2)
imshow(im)
colormap cool
title('x-ray image for hand') %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
im_conv=convn(im,PSF,'full');
figure(3)
imshow(im_conv)
title('x-ray image convolved with PSF') %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
psf_fft=fftshift(fft2(PSF));
im3=fft2(PSF);
fft_res=psf_fft.*im3;
figure(4)
imshow(fft_res)
title('the ruselt of FFT ') %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
im4=ifft(fft_res);
figure(5)
imshow(im4)
title('IFFT')
0 件のコメント
採用された回答
Image Analyst
2013 年 10 月 15 日
編集済み: Image Analyst
2013 年 10 月 15 日
im needs to be cast to double, and you need to use [] in imshow(fft_res, []). And you can also use conv2() instead of convn().
6 件のコメント
Image Analyst
2013 年 10 月 16 日
編集済み: Image Analyst
2013 年 10 月 16 日
See code:
clc
clear all
close all
fontSize = 20;
grayImage=imread('d:\temporary stuff\xray2.jpg');
[rows,columns, numberOfColorChannels]=size(grayImage);
if numberOfColorChannels > 1
% Convert color image to gra by taking green channel.
grayImage = grayImage(:,:,2);
end
subplot(3, 3, 1);
imshow(grayImage);
axis on;
colormap cool
title('x-ray image for hand', 'FontSize', fontSize);
% 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')
% Compute a PSF.
psfWidth = 15;
PSF = fspecial('gaussian', psfWidth, 5);
% Display PSF
subplot(3, 3, 2);
imshow(PSF, [])
title('PSF', 'FontSize', fontSize);
axis on;
colormap bone
% Blur the image
im_conv = conv2(double(grayImage),PSF,'full');
subplot(3, 3, 3);
imshow(im_conv, [])
axis on;
title('x-ray image convolved with PSF', 'FontSize', fontSize);
% Calculate FFT of the image and display it.
image_fft = fft2(grayImage);
subplot(3, 3, 4);
niceImageToDisplay = log(fftshift(real(image_fft)));
imshow(niceImageToDisplay, [])
axis on;
title('FFT of hand image.', 'FontSize', fontSize);
% Calculate FFT of the PSF and display it.
psf_fft = fft2(PSF);
subplot(3, 3, 5);
niceImageToDisplay = log(fftshift(real(psf_fft)));
imshow(niceImageToDisplay, [])
axis on;
title('FFT of PSF', 'FontSize', fontSize);
% Calculate the FFT of the blurred image and display it.
blurryImage_fft = fft2(im_conv);
subplot(3, 3, 6);
niceImageToDisplay = log(fftshift(real(blurryImage_fft)));
imshow(niceImageToDisplay, [])
axis on;
title('FFT of blurred hand image.', 'FontSize', fontSize);
% Multiply the FFT of the PSF by the FFT of the image.
p = ceil([rows-psfWidth, columns - psfWidth]/2)
fftSameSize = padarray(fftshift(psf_fft), p);
% Adjust size slightly so we can multiply them.
fftSameSize = imresize(fftSameSize, [rows, columns]);
fftProduct = fftSameSize .* fftshift(image_fft);
% Display it.
subplot(3, 3, 7);
niceImageToDisplay = log(real(fftProduct));
imshow(niceImageToDisplay, [])
axis on;
title('Product of the two FFTs.', 'FontSize', fontSize);

その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!