1 | function [H,J] = imarraysc(A, varargin) |
---|
2 | % IMARRAYSC Scale and display an array of images |
---|
3 | % H = IMARRAYSC(A) behaves as IMARRAY(A), but scales the range |
---|
4 | % of each image to fill the interval [0,1]. |
---|
5 | % |
---|
6 | % In addition to the option-value paris accepted by IMARRAY(), |
---|
7 | % the function accepts also: |
---|
8 | % |
---|
9 | % 'CLim' [[]] |
---|
10 | % If not empty, use the specified intensity range. |
---|
11 | % |
---|
12 | % See also IMARRAY(). |
---|
13 | |
---|
14 | % AUTORIGHTS |
---|
15 | % Copyright (C) 2006 Andrea Vedaldi |
---|
16 | % |
---|
17 | % This file is part of VLUtil. |
---|
18 | % |
---|
19 | % VLUtil is free software; you can redistribute it and/or modify |
---|
20 | % it under the terms of the GNU General Public License as published by |
---|
21 | % the Free Software Foundation; either version 2, or (at your option) |
---|
22 | % any later version. |
---|
23 | % |
---|
24 | % This program is distributed in the hope that it will be useful, |
---|
25 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
26 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
27 | % GNU General Public License for more details. |
---|
28 | % |
---|
29 | % You should have received a copy of the GNU General Public License |
---|
30 | % along with this program; if not, write to the Free Software Foundation, |
---|
31 | % Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
32 | |
---|
33 | reverse=1 ; |
---|
34 | spacing=0 ; |
---|
35 | clim=[] ; |
---|
36 | |
---|
37 | % Parse |
---|
38 | if(length(varargin)>1 && isnumeric(varargin{1})) |
---|
39 | spacing=varargin{1} ; |
---|
40 | varargin = { varargin{2:end} } ; |
---|
41 | end |
---|
42 | |
---|
43 | lay=[] ; |
---|
44 | |
---|
45 | for k=1:2:length(varargin) |
---|
46 | switch lower(varargin{k}) |
---|
47 | case 'layout' |
---|
48 | lay=varargin{k+1} ; |
---|
49 | case 'spacing' |
---|
50 | spacing=varargin{k+1} ; |
---|
51 | case 'clim' |
---|
52 | clim=varargin{k+1} ; |
---|
53 | otherwise |
---|
54 | error(['Unknown option ''', varargin{k}, '''']) ; |
---|
55 | end |
---|
56 | end |
---|
57 | |
---|
58 | if ndims(A) <= 3 |
---|
59 | d = 1 ; |
---|
60 | [Mi,Ni,K] = size(A) ; |
---|
61 | else |
---|
62 | [Mi,Ni,d,K] = size(A) ; |
---|
63 | if(d ~= 3) |
---|
64 | error(['A should be either M*N*K or M*N*3*K']); |
---|
65 | end |
---|
66 | end |
---|
67 | |
---|
68 | if isempty(lay) |
---|
69 | N = ceil(sqrt(K)) ; |
---|
70 | M = ceil(K/N) ; |
---|
71 | else |
---|
72 | M = lay(1) ; |
---|
73 | N = lay(2) ; |
---|
74 | K = min(K,M*N) ; |
---|
75 | end |
---|
76 | |
---|
77 | cdata = zeros(Mi*M + spacing*(M-1), Ni*N + spacing*(N-1), d ) ; |
---|
78 | |
---|
79 | for k=1:K |
---|
80 | p = k - 1 ; |
---|
81 | i = floor(p/N) ; |
---|
82 | if reverse |
---|
83 | i = M-1 - i ; |
---|
84 | end |
---|
85 | j = mod(p,N) ; |
---|
86 | irng = i*(Mi+spacing) + (0:Mi-1) + 1 ; |
---|
87 | jrng = j*(Ni+spacing) + (0:Ni-1) + 1 ; |
---|
88 | if d == 1 |
---|
89 | J = A(:,:,k) ; |
---|
90 | else |
---|
91 | J = A(:,:,:,k) ; |
---|
92 | end |
---|
93 | if isempty( clim ) |
---|
94 | J = J - min(J(:)) ; |
---|
95 | m = max(J(:)) ; |
---|
96 | if(m > eps) |
---|
97 | J = J / m ; |
---|
98 | end |
---|
99 | end |
---|
100 | cdata(irng,jrng,:) = J ; |
---|
101 | end |
---|
102 | |
---|
103 | if ~isempty(clim) |
---|
104 | H = imagesc(cdata,clim) ; |
---|
105 | else |
---|
106 | H = imagesc(cdata) ; |
---|
107 | end |
---|
108 | |
---|
109 | J = cdata ; |
---|