Generation of PSF and Applying it to an RGB Image

7 Ansichten (letzte 30 Tage)
Ash4Matlab
Ash4Matlab am 7 Jun. 2020
Bearbeitet: Ash4Matlab am 7 Jun. 2020
I am trying to generate a PSF from a given data (Phase in radians) and convolve it an RGB image to observe the blurring. But unable to get it right. I would appreciate if I know what would be probably wrong here.
I have provided the code below. It needs to have the attached files while running.
Thanks in advance.
clc;clear;
close all
load Phase.mat
%% Mask
N = size(Phase,1);
x = -N/2:N/2-1;
y = -N/2:N/2-1;
D = 40;
r = length(x);
c = length(y);
Mask = zeros(r,c);
for i=1:r
for j=1:c
if((i-r/2)^2+(j-c/2)^2)^(0.5)<=D
Mask(i,j)=1;
elseif ((i-r/2)^2+(j-c/2)^2)^(0.5)>D
Mask(i,j)=0;
elseif ((i-r/2)^2+(j-c/2)^2)^(0.5)== D
Mask(i,j)=0.5;
end
end
end
%% Point Spread Function
PhaseFT = fftshift(fft2(exp(1i*Phase)));
PSF = abs(PhaseFT.*Mask).^2;
%% Applying PSF to an Image
TestImage = rgb2gray(imread('HST.png'));
Im = conv2(TestImage,PSF,'valid');
figure(1)
imshow(TestImage)
figure(2)
imshow(real(Im))

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by