-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathconvolution.m
53 lines (47 loc) · 1.44 KB
/
convolution.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function [convolution]=convolution(PSF)
%{
Created by Sergio Bonaque-Gonzalez. Optical Engineer.
This function convolves a PSF with and extended object.
INPUTS:
PSF: the point spread function.
OUTPUTS:
Convolucion: the convolution of the PSF with the object.
%}
%Open an image
myExtract=imread('wooptix.tif');
objeto = myExtract(:,:,1);
%Resize matrix size
[p1, p2] = size(PSF);
[o1,o2]=size(objeto);
if p1>o1
if rem((p1-o1),2)==0
objeto=padarray(objeto,[((p1-o1)/2),((p2-o2)/2)]);
else
objeto(:,end)=[];
objeto(end,:)=[];
[o1,o2]=size(objeto);
objeto=padarray(objeto,[((p1-o1)/2),((p2-o2)/2)]);
end
elseif p1<o1
if rem((o1-p1),2)==0
objeto(end-((o1-p1)/2)+1:end,:)=[];
objeto(:,end-((o1-p1)/2)+1:end)=[];
objeto(:,1:((o1-p1)/2))=[];
objeto(1:((o1-p1)/2),:)=[];
else
objeto(:,end)=[];
objeto(end,:)=[];
[o1,o2]=size(objeto);
objeto(end-((o1-p1)/2)+1:end,:)=[];
objeto(:,end-((o1-p1)/2)+1:end)=[];
objeto(:,1:((o1-p1)/2))=[];
objeto(1:((o1-p1)/2),:)=[];
end
end
%Make the product in the frequencies space
product =fftshift(fft2(double(objeto))) .* fftshift(fft2(double(PSF)));
%Coming back to the image space.
convolution = abs(fftshift(ifft2(double(product))));
clear product;
convolution = convolution./max(max(convolution));