-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadIm.m
55 lines (49 loc) · 1.26 KB
/
LoadIm.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
54
function [ im, ii_im ] = LoadIm( im_fname, varargin )
%LoadIm Load image
% Input:
% 1) Filename of an image
% 2) if varargin{1} is set to 1, sanity check is enabled
% Output: Two arrays
% 1) Normalized version of the pixel data of the image
% 2) It's integral image
% Read in image
im = imread(im_fname);
im = double(im);
[x, y] = size(im);
% Image normalization orig
im = im(:);
mu = mean(im);
sigma = std(im);
if sigma == 0
sigma = 1;
end
im = (im - mu) / sigma;
dflag = 0;
if nargin > 1
dflag = 1;
end
% Sanity check
if dflag == 1
if (round(mean(im)) == 0) && (round(std(im)) == 1)
disp('[Success] LoadIm (Sanity check): im is normalized');
else
msg = '[Fail] LoadIm (Sanity check): im is not normalized';
error(msg);
end
end
% Reshape back to original dimensions
im = reshape(im, [x, y]);
% Compute the integral image
ii_im = cumsum(cumsum(im, 1), 2);
%
% im = double(imread(im_fname));
% mu = mean(im(:));
% sd = std(im(:));
% if sd == 0
% sd = 1;
% end
% n_im = (im - mu) / sd;
%
% ii_im = cumsum(cumsum(n_im, 2));
% im = n_im;
end