1 | function J = imdown(I,method) |
---|
2 | % IMDOWN Downsample image |
---|
3 | % J = IMDOWN(I,'sample') downsamples the image I by half by |
---|
4 | % discarding each other pixel. |
---|
5 | % |
---|
6 | % IMDOWN(I,'avg') downsmples by averaging groups of four pixels. |
---|
7 | % |
---|
8 | % The image is always converted to double format. |
---|
9 | % |
---|
10 | % See also IMUP(). |
---|
11 | |
---|
12 | % AUTORIGHTS |
---|
13 | % Copyright (C) 2006 Andrea Vedaldi |
---|
14 | % |
---|
15 | % This file is part of VLUtil. |
---|
16 | % |
---|
17 | % VLUtil is free software; you can redistribute it and/or modify |
---|
18 | % it under the terms of the GNU General Public License as published by |
---|
19 | % the Free Software Foundation; either version 2, or (at your option) |
---|
20 | % any later version. |
---|
21 | % |
---|
22 | % This program is distributed in the hope that it will be useful, |
---|
23 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
24 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
25 | % GNU General Public License for more details. |
---|
26 | % |
---|
27 | % You should have received a copy of the GNU General Public License |
---|
28 | % along with this program; if not, write to the Free Software Foundation, |
---|
29 | % Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
30 | |
---|
31 | I = rgb2double(I) ; |
---|
32 | |
---|
33 | if nargin < 2 |
---|
34 | method = 'sample' ; |
---|
35 | end |
---|
36 | |
---|
37 | switch method |
---|
38 | case 'sample' |
---|
39 | J = I(1:2:end,1:2:end,:) ; |
---|
40 | |
---|
41 | case 'avg' |
---|
42 | J = ... |
---|
43 | I(1:2:end-1,1:2:end-1,:) + ... |
---|
44 | I(2:2:end,1:2:end-1,:) + ... |
---|
45 | I(1:2:end-1,2:2:end,:) + ... |
---|
46 | I(2:2:end,2:2:end,:) ; |
---|
47 | J = J / 4 ; |
---|
48 | end |
---|