annotate _FullBNT/KPMtools/imresizeAspect.m @ 9:4ea6619cb3f5 tip

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