-
Notifications
You must be signed in to change notification settings - Fork 6
/
get_image.m
31 lines (24 loc) · 860 Bytes
/
get_image.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
function [ im ] = get_image( image_path ,patch_width,patch_height,options)
%% get_image , will load the image from image_path
% - patch_width,patch_height can be used to crop certain part of an
% image.
% If you want to load the whole image, set these values to -1
%
% - options can be used to pass extra parameters, like applying a
% particular transformation to the image after being loaded
im = imread(image_path);
if(size(im,3)>1)
im =double(rgb2gray(im));
else
im =double(im);
end
if(patch_width ~= -1)
row_index = round((size(im,1)-patch_width)/2);
col_index = round((size(im,2)-patch_height)/2);
im = im(row_index:row_index+patch_width-1,col_index:col_index+patch_height-1);
end
im_mean = mean(im(:));
im_std = std(im(:));
im = im - im_mean;
im = im / im_std;
end