comparison toolboxes/FullBNT-1.0.7/KPMtools/imresizeAspect.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function img = imresizeAspect(img, maxSize)
2 % function img = imresizeAspect(img, maxSize)
3 % If image is larger than max size, reduce size, preserving aspect ratio of input.
4 %
5 % If size(input) = [y x] and maxSize = [yy xx],
6 % then size(output) is given by the following (where a=y/x)
7 % if y<yy & x<xx then [y x]
8 % else if a<1 then [a*xx xx]
9 % else [yy yy/a]
10
11 % For why we use bilinear,
12 % See http://nickyguides.digital-digest.com/bilinear-vs-bicubic.htm
13
14 if isempty(maxSize), return; end
15
16 [y x c] = size(img);
17 a= y/x;
18 yy = maxSize(1); xx = maxSize(2);
19 if y <= yy & x <= xx
20 % no-op
21 else
22 if a < 1
23 img = imresize(img, ceil([a*xx xx]), 'bilinear');
24 else
25 img = imresize(img, ceil([yy yy/a]), 'bilinear');
26 end
27 fprintf('resizing from %dx%d to %dx%d\n', y, x, size(img,1), size(img,2));
28 end
29
30
31 %test
32 if 0
33 maxSize = [240 320];
34 %img = imread('C:\Images\Wearables\web_static_office\8.jpg');
35 %img = imread('C:\Images\Wearables\web_static_office\billandkirsten.jpg');
36 %img = imread('C:\Images\Wearables\web_static_street_april\p5.jpg');
37 img = imread('C:\Images\Wearables\Database_static_street\art11.jpg');
38 img2 = imresizeAspect(img, maxSize);
39 figure(1); clf; imshow(img)
40 figure(2); clf; imshow(img2)
41 fprintf('%dx%d (%5.3f) to %dx%d (%5.3f)\n', ...
42 size(img,1), size(img,2), size(img,1)/size(img,2), ...
43 size(img2,1), size(img2,2), size(img2,1)/size(img2,2));
44 end