forked from ndwork/dworkLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimColorResize.m
More file actions
50 lines (43 loc) · 1.32 KB
/
imColorResize.m
File metadata and controls
50 lines (43 loc) · 1.32 KB
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
function out = imColorResize( img, newSize, varargin )
% out = imColorResize( img, newSize, varargin )
%
% Inputs:
% img - original color image
% newSize - 1, 2, or 3 element array specifying new array size;
% If 1 element, then assumed to be the scale
% 3rd element must be 3. If two elements are supplied, assumed 3rd
% element is 3.
%
% Optional Inputs:
% All optional inputs accepted by imresize are accepted
%
% Written by Nicholas Dwork - Copyright 2016
%
% This software is offered under the GNU General Public License 3.0. It
% is offered without any warranty expressed or implied, including the
% implied warranties of merchantability or fitness for a particular
% purpose.
sImg = size(img);
if numel( newSize ) == 1
newChannelSize = sImg(1:2) * newSize;
else
newChannelSize = newSize(1:2);
end
if ismatrix( img )
nChannels = 1;
else
nChannels = sImg(3);
end
if isempty( gcp( 'nocreate' ) )
out = zeros( [newChannelSize nChannels] );
for ch = 1 : nChannels
out(:,:,ch) = imresize( img(:,:,ch), newChannelSize, varargin{:} );
end
else
out = cell( 1, 1, nChannels );
parfor ch = 1 : nChannels
out{ch} = imresize( img(:,:,ch), newChannelSize, varargin{:} ); %#ok<PFBNS>
end
out = cell2mat( out );
end
end