-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetIntensity.m
More file actions
executable file
·54 lines (40 loc) · 1.49 KB
/
getIntensity.m
File metadata and controls
executable file
·54 lines (40 loc) · 1.49 KB
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
54
function Iout = getIntensity(X,im)
%Iout = getIntensity(X,im)
%This function calculates the intensity values in 'im' and the
%points X; X in a [N 2] matrix of points and it assumes that the
%coordinate axis is in the lower left.
%Iout is a [N 1] vector of intensity values at the corresponding
%points based on bilinear interpolation.
[nrow,ncol] = size(im);
%Convert X into (row,col) coordinates
Xidx = [X(:,2) X(:,1)];
%Find the indices of the four neighboring pixels by Rounding
%[rmin rmax cmin cmax]
IDX = [floor(Xidx(:,1)) ceil(Xidx(:,1)) floor(Xidx(:,2)) ceil(Xidx(:,2))];
%Get rid of sample points that are outside the image boundary
ii = find(IDX(:,1) <= 0);
IDX(ii,:) = [];
Xidx(ii,:) = [];
ii = find(IDX(:,2) > nrow);
IDX(ii,:) = [];
Xidx(ii,:) = [];
ii = find(IDX(:,3) <= 0);
IDX(ii,:) = [];
Xidx(ii,:) = [];
ii = find(IDX(:,4) > ncol);
IDX(ii,:) = [];
Xidx(ii,:) = [];
%Calculate matrix of weights w = (1-abs(x-i))*(1-abs(y-j))
% W is a [N 4] matrix
W = [(1-abs(Xidx(:,1) - IDX(:,1))).*(1-abs(Xidx(:,2) - IDX(:,3)))...
(1-abs(Xidx(:,1) - IDX(:,1))).*(1-abs(Xidx(:,2) - IDX(:,4)))...
(1-abs(Xidx(:,1) - IDX(:,2))).*(1-abs(Xidx(:,2) - IDX(:,3)))...
(1-abs(Xidx(:,1) - IDX(:,2))).*(1-abs(Xidx(:,2) - IDX(:,4)))];
%now create a matrix of image intensities with dimension [N 4] to
%perform the inner product
I = zeros(size(W));
for k = 1:size(I,1)
I(k,:) = [im(IDX(k,1),IDX(k,3)) im(IDX(k,1),IDX(k,4)) im(IDX(k,2),IDX(k,3)) ...
im(IDX(k,2),IDX(k,4))];
end
Iout = sum(W.*I,2);