plateform
stringclasses
1 value
repo_name
stringlengths
13
113
name
stringlengths
3
74
ext
stringclasses
1 value
path
stringlengths
12
229
size
int64
23
843k
source_encoding
stringclasses
9 values
md5
stringlengths
32
32
text
stringlengths
23
843k
github
jbhuang0604/LapSRN-master
mkImpulse.m
.m
LapSRN-master/utils/matlabPyrTools/mkImpulse.m
529
utf_8
cf6f3809cb123791501bb0e92845a0c6
% IM = mkImpulse(SIZE, ORIGIN, AMPLITUDE) % % Compute a matrix of dimension SIZE (a [Y X] 2-vector, or a scalar) % containing a single non-zero entry, at position ORIGIN (defaults to % ceil(size/2)), of value AMPLITUDE (defaults to 1). % Eero Simoncelli, 6/96. function [res] = mkImpulse(sz, origin, amplitude) sz = sz(:)'; if (size(sz,2) == 1) sz = [sz sz]; end if (exist('origin') ~= 1) origin = ceil(sz/2); end if (exist('amplitude') ~= 1) amplitude = 1; end res = zeros(sz); res(origin(1),origin(2)) = amplitude;
github
jbhuang0604/LapSRN-master
rconv2.m
.m
LapSRN-master/utils/matlabPyrTools/rconv2.m
1,435
utf_8
da3a54d6c7b1ac17c78eab0a4a7648d9
% RES = RCONV2(MTX1, MTX2, CTR) % % Convolution of two matrices, with boundaries handled via reflection % about the edge pixels. Result will be of size of LARGER matrix. % % The origin of the smaller matrix is assumed to be its center. % For even dimensions, the origin is determined by the CTR (optional) % argument: % CTR origin % 0 DIM/2 (default) % 1 (DIM/2)+1 % Eero Simoncelli, 6/96. function c = rconv2(a,b,ctr) if (exist('ctr') ~= 1) ctr = 0; end if (( size(a,1) >= size(b,1) ) & ( size(a,2) >= size(b,2) )) large = a; small = b; elseif (( size(a,1) <= size(b,1) ) & ( size(a,2) <= size(b,2) )) large = b; small = a; else error('one arg must be larger than the other in both dimensions!'); end ly = size(large,1); lx = size(large,2); sy = size(small,1); sx = size(small,2); %% These values are one less than the index of the small mtx that falls on %% the border pixel of the large matrix when computing the first %% convolution response sample: sy2 = floor((sy+ctr-1)/2); sx2 = floor((sx+ctr-1)/2); % pad with reflected copies clarge = [ large(sy-sy2:-1:2,sx-sx2:-1:2), large(sy-sy2:-1:2,:), ... large(sy-sy2:-1:2,lx-1:-1:lx-sx2); ... large(:,sx-sx2:-1:2), large, large(:,lx-1:-1:lx-sx2); ... large(ly-1:-1:ly-sy2,sx-sx2:-1:2), ... large(ly-1:-1:ly-sy2,:), ... large(ly-1:-1:ly-sy2,lx-1:-1:lx-sx2) ]; c = conv2(clarge,small,'valid');
github
jbhuang0604/LapSRN-master
mkR.m
.m
LapSRN-master/utils/matlabPyrTools/mkR.m
775
utf_8
504bc90f67c72730edc4a9d86630bdf2
% IM = mkR(SIZE, EXPT, ORIGIN) % % Compute a matrix of dimension SIZE (a [Y X] 2-vector, or a scalar) % containing samples of a radial ramp function, raised to power EXPT % (default = 1), with given ORIGIN (default = (size+1)/2, [1 1] = % upper left). All but the first argument are optional. % Eero Simoncelli, 6/96. function [res] = mkR(sz, expt, origin) sz = sz(:); if (size(sz,1) == 1) sz = [sz,sz]; end % ----------------------------------------------------------------- % OPTIONAL args: if (exist('expt') ~= 1) expt = 1; end if (exist('origin') ~= 1) origin = (sz+1)/2; end % ----------------------------------------------------------------- [xramp,yramp] = meshgrid( [1:sz(2)]-origin(2), [1:sz(1)]-origin(1) ); res = (xramp.^2 + yramp.^2).^(expt/2);
github
jbhuang0604/LapSRN-master
blur.m
.m
LapSRN-master/utils/matlabPyrTools/blur.m
1,731
utf_8
a2dc57fdfe85f98549b2f7ddf721c298
% RES = blur(IM, LEVELS, FILT) % % Blur an image, by filtering and downsampling LEVELS times % (default=1), followed by upsampling and filtering LEVELS times. The % blurring is done with filter kernel specified by FILT (default = % 'binom5'), which can be a string (to be passed to namedFilter), a % vector (applied separably as a 1D convolution kernel in X and Y), or % a matrix (applied as a 2D convolution kernel). The downsampling is % always by 2 in each direction. % Eero Simoncelli, 3/04. function res = blur(im, nlevs, filt) %------------------------------------------------------------ %% OPTIONAL ARGS: if (exist('nlevs') ~= 1) nlevs = 1; end if (exist('filt') ~= 1) filt = 'binom5'; end %------------------------------------------------------------ if isstr(filt) filt = namedFilter(filt); end filt = filt/sum(filt(:)); if nlevs > 0 if (any(size(im)==1)) if (~any(size(filt)==1)) error('Cant apply 2D filter to 1D signal'); end if (size(im,2)==1) filt = filt(:); else filt = filt(:)'; end in = corrDn(im,filt,'reflect1',(size(im)~=1)+1); out = blur(in, nlevs-1, filt); res = upConv(out, filt, 'reflect1', (size(im)~=1)+1, [1 1], size(im)); elseif (any(size(filt)==1)) filt = filt(:); in = corrDn(im,filt,'reflect1',[2 1]); in = corrDn(in,filt','reflect1',[1 2]); out = blur(in, nlevs-1, filt); res = upConv(out, filt', 'reflect1', [1 2], [1 1], [size(out,1),size(im,2)]); res = upConv(res, filt, 'reflect1', [2 1], [1 1], size(im)); else in = corrDn(im,filt,'reflect1',[2 2]); out = blur(in, nlevs-1, filt); res = upConv(out, filt, 'reflect1', [2 2], [1 1], size(im)); end else res = im; end
github
jbhuang0604/LapSRN-master
pyrBand.m
.m
LapSRN-master/utils/matlabPyrTools/pyrBand.m
395
utf_8
39c1e3772426a1362119d302d9767a24
% RES = pyrBand(PYR, INDICES, BAND_NUM) % % Access a subband from a pyramid (gaussian, laplacian, QMF/wavelet, % or steerable). Subbands are numbered consecutively, from finest % (highest spatial frequency) to coarsest (lowest spatial frequency). % Eero Simoncelli, 6/96. function res = pyrBand(pyr, pind, band) res = reshape( pyr(pyrBandIndices(pind,band)), pind(band,1), pind(band,2) );
github
jbhuang0604/LapSRN-master
kurt2.m
.m
LapSRN-master/utils/matlabPyrTools/kurt2.m
551
utf_8
cd20c1a5155cba8de454011552ec4f2a
% K = KURT2(MTX,MEAN,VAR) % % Sample kurtosis (fourth moment divided by squared variance) % of a matrix. Kurtosis of a Gaussian distribution is 3. % MEAN (optional) and VAR (optional) make the computation faster. % Eero Simoncelli, 6/96. function res = kurt2(mtx, mn, v) if (exist('mn') ~= 1) mn = mean(mean(mtx)); end if (exist('v') ~= 1) v = var2(mtx,mn); end if (isreal(mtx)) res = mean(mean(abs(mtx-mn).^4)) / (v^2); else res = mean(mean(real(mtx-mn).^4)) / (real(v)^2) + ... i*mean(mean(imag(mtx-mn).^4)) / (imag(v)^2); end
github
jbhuang0604/LapSRN-master
buildSpyr.m
.m
LapSRN-master/utils/matlabPyrTools/buildSpyr.m
2,064
utf_8
b0caf60e63a52aa734956dd74ea39f95
% [PYR, INDICES, STEERMTX, HARMONICS] = buildSpyr(IM, HEIGHT, FILTFILE, EDGES) % % Construct a steerable pyramid on matrix IM. Convolutions are % done with spatial filters. % % HEIGHT (optional) specifies the number of pyramid levels to build. Default % is maxPyrHt(size(IM),size(FILT)). % You can also specify 'auto' to use this value. % % FILTFILE (optional) should be a string referring to an m-file that % returns the rfilters. (examples: 'sp0Filters', 'sp1Filters', % 'sp3Filters','sp5Filters'. default = 'sp1Filters'). EDGES specifies % edge-handling, and defaults to 'reflect1' (see corrDn). % % PYR is a vector containing the N pyramid subbands, ordered from fine % to coarse. INDICES is an Nx2 matrix containing the sizes of % each subband. This is compatible with the MatLab Wavelet toolbox. % See the function STEER for a description of STEERMTX and HARMONICS. % Eero Simoncelli, 6/96. % See http://www.cis.upenn.edu/~eero/steerpyr.html for more % information about the Steerable Pyramid image decomposition. function [pyr,pind,steermtx,harmonics] = buildSpyr(im, ht, filtfile, edges) %----------------------------------------------------------------- %% DEFAULTS: if (exist('filtfile') ~= 1) filtfile = 'sp1Filters'; end if (exist('edges') ~= 1) edges= 'reflect1'; end if (isstr(filtfile) & (exist(filtfile) == 2)) [lo0filt,hi0filt,lofilt,bfilts,steermtx,harmonics] = eval(filtfile); else fprintf(1,'\nUse buildSFpyr for pyramids with arbitrary numbers of orientation bands.\n'); error('FILTFILE argument must be the name of an M-file containing SPYR filters.'); end max_ht = maxPyrHt(size(im), size(lofilt,1)); if ( (exist('ht') ~= 1) | (ht == 'auto') ) ht = max_ht; else if (ht > max_ht) error(sprintf('Cannot build pyramid higher than %d levels.',max_ht)); end end %----------------------------------------------------------------- hi0 = corrDn(im, hi0filt, edges); lo0 = corrDn(im, lo0filt, edges); [pyr,pind] = buildSpyrLevs(lo0, ht, lofilt, bfilts, edges); pyr = [hi0(:) ; pyr]; pind = [size(hi0); pind];
github
jbhuang0604/LapSRN-master
setPyrBand.m
.m
LapSRN-master/utils/matlabPyrTools/setPyrBand.m
1,049
utf_8
76554eb735e969097a4723a508facd37
% NEWPYR = setPyrBand(PYR, INDICES, NEWBAND, BAND_NUM) % % Insert an image (BAND) into a pyramid (gaussian, laplacian, QMF/wavelet, % or steerable). Subbands are numbered consecutively, from finest % (highest spatial frequency) to coarsest (lowest spatial frequency). % Eero Simoncelli, 1/03. function pyr = setPyrBand(pyr, pind, band, bandNum) %% Check: PIND a valid index matrix? if ( ~(ndims(pind) == 2) | ~(size(pind,2) == 2) | ~all(pind==round(pind)) ) pind error('pyrTools:badArg',... 'PIND argument is not an Nbands X 2 matrix of integers'); end %% Check: PIND consistent with size of PYR? if ( length(pyr) ~= sum(prod(pind,2)) ) error('pyrTools:badPyr',... 'Pyramid data vector length is inconsistent with index matrix PIND'); end %% Check: size of BAND consistent with desired BANDNUM? if (~all(size(band) == pind(bandNum,:))) size(band) pind(bandNum,:) error('pyrTools:badArg',... 'size of BAND to be inserted is inconsistent with BAND_NUM'); end pyr(pyrBandIndices(pind,bandNum)) = vectify(band);
github
jbhuang0604/LapSRN-master
var2.m
.m
LapSRN-master/utils/matlabPyrTools/var2.m
390
utf_8
de26727e055081aa670024c273f0e885
% V = VAR2(MTX,MEAN) % % Sample variance of a matrix. % Passing MEAN (optional) makes the calculation faster. function res = var2(mtx, mn) if (exist('mn') ~= 1) mn = mean2(mtx); end if (isreal(mtx)) res = sum(sum(abs(mtx-mn).^2)) / max((prod(size(mtx)) - 1),1); else res = sum(sum(real(mtx-mn).^2)) + i*sum(sum(imag(mtx-mn).^2)); res = res / max((prod(size(mtx)) - 1),1); end
github
jbhuang0604/LapSRN-master
reconSFpyrLevs.m
.m
LapSRN-master/utils/matlabPyrTools/reconSFpyrLevs.m
2,016
utf_8
ff83a4f3d2f0927dcaa8851535e6b20a
% RESDFT = reconSFpyrLevs(PYR,INDICES,LOGRAD,XRCOS,YRCOS,ANGLE,NBANDS,LEVS,BANDS) % % Recursive function for reconstructing levels of a steerable pyramid % representation. This is called by reconSFpyr, and is not usually % called directly. % Eero Simoncelli, 5/97. function resdft = reconSFpyrLevs(pyr,pind,log_rad,Xrcos,Yrcos,angle,nbands,levs,bands); lo_ind = nbands+1; dims = pind(1,:); ctr = ceil((dims+0.5)/2); % log_rad = log_rad + 1; Xrcos = Xrcos - log2(2); % shift origin of lut by 1 octave. if any(levs > 1) lodims = ceil((dims-0.5)/2); loctr = ceil((lodims+0.5)/2); lostart = ctr-loctr+1; loend = lostart+lodims-1; nlog_rad = log_rad(lostart(1):loend(1),lostart(2):loend(2)); nangle = angle(lostart(1):loend(1),lostart(2):loend(2)); if (size(pind,1) > lo_ind) nresdft = reconSFpyrLevs( pyr(1+sum(prod(pind(1:lo_ind-1,:)')):size(pyr,1)),... pind(lo_ind:size(pind,1),:), ... nlog_rad, Xrcos, Yrcos, nangle, nbands,levs-1, bands); else nresdft = fftshift(fft2(pyrBand(pyr,pind,lo_ind))); end YIrcos = sqrt(abs(1.0 - Yrcos.^2)); lomask = pointOp(nlog_rad, YIrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0); resdft = zeros(dims); resdft(lostart(1):loend(1),lostart(2):loend(2)) = nresdft .* lomask; else resdft = zeros(dims); end if any(levs == 1) lutsize = 1024; Xcosn = pi*[-(2*lutsize+1):(lutsize+1)]/lutsize; % [-2*pi:pi] order = nbands-1; %% divide by sqrt(sum_(n=0)^(N-1) cos(pi*n/N)^(2(N-1)) ) const = (2^(2*order))*(factorial(order)^2)/(nbands*factorial(2*order)); Ycosn = sqrt(const) * (cos(Xcosn)).^order; himask = pointOp(log_rad, Yrcos, Xrcos(1), Xrcos(2)-Xrcos(1),0); ind = 1; for b = 1:nbands if any(bands == b) anglemask = pointOp(angle,Ycosn,Xcosn(1)+pi*(b-1)/nbands,Xcosn(2)-Xcosn(1)); band = reshape(pyr(ind:ind+prod(dims)-1), dims(1), dims(2)); banddft = fftshift(fft2(band)); resdft = resdft + (sqrt(-1))^(nbands-1) * banddft.*anglemask.*himask; end ind = ind + prod(dims); end end
github
jbhuang0604/LapSRN-master
rcosFn.m
.m
LapSRN-master/utils/matlabPyrTools/rcosFn.m
1,122
utf_8
36283e0a34f1baf7ea2c5e6cb23aab89
% [X, Y] = rcosFn(WIDTH, POSITION, VALUES) % % Return a lookup table (suitable for use by INTERP1) % containing a "raised cosine" soft threshold function: % % Y = VALUES(1) + (VALUES(2)-VALUES(1)) * % cos^2( PI/2 * (X - POSITION + WIDTH)/WIDTH ) % % WIDTH is the width of the region over which the transition occurs % (default = 1). POSITION is the location of the center of the % threshold (default = 0). VALUES (default = [0,1]) specifies the % values to the left and right of the transition. % Eero Simoncelli, 7/96. function [X, Y] = rcosFn(width,position,values) %------------------------------------------------------------ % OPTIONAL ARGS: if (exist('width') ~= 1) width = 1; end if (exist('position') ~= 1) position = 0; end if (exist('values') ~= 1) values = [0,1]; end %------------------------------------------------------------ sz = 256; %% arbitrary! X = pi * [-sz-1:1] / (2*sz); Y = values(1) + (values(2)-values(1)) * cos(X).^2; % Make sure end values are repeated, for extrapolation... Y(1) = Y(2); Y(sz+3) = Y(sz+2); X = position + (2*width/pi) * (X + pi/4);
github
jbhuang0604/LapSRN-master
wpyrLev.m
.m
LapSRN-master/utils/matlabPyrTools/wpyrLev.m
729
utf_8
77f309b76f98f3421e786fde4fe2d429
% [LEV,IND] = wpyrLev(PYR,INDICES,LEVEL) % % Access a level from a separable QMF/wavelet pyramid. % Return as an SxB matrix, B = number of bands, S = total size of a band. % Also returns an Bx2 matrix containing dimensions of the subbands. % Eero Simoncelli, 6/96. function [lev,ind] = wpyrLev(pyr,pind,level) if ((pind(1,1) == 1) | (pind(1,2) ==1)) nbands = 1; else nbands = 3; end if ((level > wpyrHt(pind)) | (level < 1)) error(sprintf('Level number must be in the range [1, %d].', wpyrHt(pind))); end firstband = 1 + nbands*(level-1) firstind = 1; for l=1:firstband-1 firstind = firstind + prod(pind(l,:)); end ind = pind(firstband:firstband+nbands-1,:); lev = pyr(firstind:firstind+sum(prod(ind'))-1);
github
jbhuang0604/LapSRN-master
binomialFilter.m
.m
LapSRN-master/utils/matlabPyrTools/binomialFilter.m
309
utf_8
47b67219b2519bd65a435f3df318d41a
% KERNEL = binomialFilter(size) % % Returns a vector of binomial coefficients of order (size-1) . % Eero Simoncelli, 2/97. function [kernel] = binomialFilter(sz) if (sz < 2) error('size argument must be larger than 1'); end kernel = [0.5 0.5]'; for n=1:sz-2 kernel = conv([0.5 0.5]', kernel); end
github
jbhuang0604/LapSRN-master
cconv2.m
.m
LapSRN-master/utils/matlabPyrTools/cconv2.m
1,325
utf_8
8e564b623ba5cebd51e585eac6c66ba8
% RES = CCONV2(MTX1, MTX2, CTR) % % Circular convolution of two matrices. Result will be of size of % LARGER vector. % % The origin of the smaller matrix is assumed to be its center. % For even dimensions, the origin is determined by the CTR (optional) % argument: % CTR origin % 0 DIM/2 (default) % 1 (DIM/2)+1 % Eero Simoncelli, 6/96. Modified 2/97. function c = cconv2(a,b,ctr) if (exist('ctr') ~= 1) ctr = 0; end if (( size(a,1) >= size(b,1) ) & ( size(a,2) >= size(b,2) )) large = a; small = b; elseif (( size(a,1) <= size(b,1) ) & ( size(a,2) <= size(b,2) )) large = b; small = a; else error('one arg must be larger than the other in both dimensions!'); end ly = size(large,1); lx = size(large,2); sy = size(small,1); sx = size(small,2); %% These values are the index of the small mtx that falls on the %% border pixel of the large matrix when computing the first %% convolution response sample: sy2 = floor((sy+ctr+1)/2); sx2 = floor((sx+ctr+1)/2); % pad: clarge = [ ... large(ly-sy+sy2+1:ly,lx-sx+sx2+1:lx), large(ly-sy+sy2+1:ly,:), ... large(ly-sy+sy2+1:ly,1:sx2-1); ... large(:,lx-sx+sx2+1:lx), large, large(:,1:sx2-1); ... large(1:sy2-1,lx-sx+sx2+1:lx), ... large(1:sy2-1,:), ... large(1:sy2-1,1:sx2-1) ]; c = conv2(clarge,small,'valid');
github
jbhuang0604/LapSRN-master
reconSCFpyr.m
.m
LapSRN-master/utils/matlabPyrTools/reconSCFpyr.m
4,475
utf_8
a0a6a06af4b5c9f7aa195bb8188fc754
% RES = reconSCFpyr(PYR, INDICES, LEVS, BANDS, TWIDTH) % % The inverse of buildSCFpyr: Reconstruct image from its complex steerable pyramid representation, % in the Fourier domain. % % The image is reconstructed by forcing the complex subbands to be analytic % (zero on half of the 2D Fourier plane, as they are supossed to be unless % they have being modified), and reconstructing from the real part of those % analytic subbands. That is equivalent to compute the Hilbert transforms of % the imaginary parts of the subbands, average them with their real % counterparts, and then reconstructing from the resulting real subbands. % % PYR is a vector containing the N pyramid subbands, ordered from fine % to coarse. INDICES is an Nx2 matrix containing the sizes of % each subband. This is compatible with the MatLab Wavelet toolbox. % % LEVS (optional) should be a list of levels to include, or the string % 'all' (default). 0 corresonds to the residual highpass subband. % 1 corresponds to the finest oriented scale. The lowpass band % corresponds to number spyrHt(INDICES)+1. % % BANDS (optional) should be a list of bands to include, or the string % 'all' (default). 1 = vertical, rest proceeding anti-clockwise. % % TWIDTH is the width of the transition region of the radial lowpass % function, in octaves (default = 1, which gives a raised cosine for % the bandpass filters). % Javier Portilla, 7/04, basing on Eero Simoncelli's Matlab Pyrtools code % and our common code on texture synthesis (textureSynthesis.m). function res = reconSCFpyr(pyr, indices, levs, bands, twidth) %%------------------------------------------------------------ %% DEFAULTS: if ~exist('levs'), levs = 'all'; end if ~exist('bands') bands = 'all'; end if ~exist('twidth'), twidth = 1; elseif (twidth <= 0) fprintf(1,'Warning: TWIDTH must be positive. Setting to 1.\n'); twidth = 1; end %%------------------------------------------------------------ pind = indices; Nsc = log2(pind(1,1)/pind(end,1)); Nor = (size(pind,1)-2)/Nsc; for nsc = 1:Nsc, firstBnum = (nsc-1)*Nor+2; %% Re-create analytic subbands dims = pind(firstBnum,:); ctr = ceil((dims+0.5)/2); ang = mkAngle(dims, 0, ctr); ang(ctr(1),ctr(2)) = -pi/2; for nor = 1:Nor, nband = (nsc-1)*Nor+nor+1; ind = pyrBandIndices(pind,nband); ch = pyrBand(pyr, pind, nband); ang0 = pi*(nor-1)/Nor; xang = mod(ang-ang0+pi, 2*pi) - pi; amask = 2*(abs(xang) < pi/2) + (abs(xang) == pi/2); amask(ctr(1),ctr(2)) = 1; amask(:,1) = 1; amask(1,:) = 1; amask = fftshift(amask); ch = ifft2(amask.*fft2(ch)); % "Analytic" version %f = 1.000008; % With this factor the reconstruction SNR goes up around 6 dB! f = 1; ch = f*0.5*real(ch); % real part pyr(ind) = ch; end % nor end % nsc res = reconSFpyr(pyr, indices, levs, bands, twidth);
github
jbhuang0604/LapSRN-master
buildSCFpyr.m
.m
LapSRN-master/utils/matlabPyrTools/buildSCFpyr.m
2,713
utf_8
d94b4004138b50b6651511e8ba6ccb93
% [PYR, INDICES, STEERMTX, HARMONICS] = buildSCFpyr(IM, HEIGHT, ORDER, TWIDTH) % % This is a modified version of buildSFpyr, that constructs a % complex-valued steerable pyramid using Hilbert-transform pairs % of filters. Note that the imaginary parts will *not* be steerable. % % To reconstruct from this representation, either call reconSFpyr % on the real part of the pyramid, *or* call reconSCFpyr which will % use both real and imaginary parts (forcing analyticity). % % Description of this transform appears in: Portilla & Simoncelli, % Int'l Journal of Computer Vision, 40(1):49-71, Oct 2000. % Further information: http://www.cns.nyu.edu/~eero/STEERPYR/ % Original code: Eero Simoncelli, 5/97. % Modified by Javier Portilla to return complex (quadrature pair) channels, % 9/97. function [pyr,pind,steermtx,harmonics] = buildSCFpyr(im, ht, order, twidth) %----------------------------------------------------------------- %% DEFAULTS: max_ht = floor(log2(min(size(im)))) - 2; if (exist('ht') ~= 1) ht = max_ht; else if (ht > max_ht) error(sprintf('Cannot build pyramid higher than %d levels.',max_ht)); end end if (exist('order') ~= 1) order = 3; elseif ((order > 15) | (order < 0)) fprintf(1,'Warning: ORDER must be an integer in the range [0,15]. Truncating.\n'); order = min(max(order,0),15); else order = round(order); end nbands = order+1; if (exist('twidth') ~= 1) twidth = 1; elseif (twidth <= 0) fprintf(1,'Warning: TWIDTH must be positive. Setting to 1.\n'); twidth = 1; end %----------------------------------------------------------------- %% Steering stuff: if (mod((nbands),2) == 0) harmonics = [0:(nbands/2)-1]'*2 + 1; else harmonics = [0:(nbands-1)/2]'*2; end steermtx = steer2HarmMtx(harmonics, pi*[0:nbands-1]/nbands, 'even'); %----------------------------------------------------------------- dims = size(im); ctr = ceil((dims+0.5)/2); [xramp,yramp] = meshgrid( ([1:dims(2)]-ctr(2))./(dims(2)/2), ... ([1:dims(1)]-ctr(1))./(dims(1)/2) ); angle = atan2(yramp,xramp); log_rad = sqrt(xramp.^2 + yramp.^2); log_rad(ctr(1),ctr(2)) = log_rad(ctr(1),ctr(2)-1); log_rad = log2(log_rad); %% Radial transition function (a raised cosine in log-frequency): [Xrcos,Yrcos] = rcosFn(twidth,(-twidth/2),[0 1]); Yrcos = sqrt(Yrcos); YIrcos = sqrt(1.0 - Yrcos.^2); lo0mask = pointOp(log_rad, YIrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0); imdft = fftshift(fft2(im)); lo0dft = imdft .* lo0mask; [pyr,pind] = buildSCFpyrLevs(lo0dft, log_rad, Xrcos, Yrcos, angle, ht, nbands); hi0mask = pointOp(log_rad, Yrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0); hi0dft = imdft .* hi0mask; hi0 = ifft2(ifftshift(hi0dft)); pyr = [real(hi0(:)) ; pyr]; pind = [size(hi0); pind];
github
jbhuang0604/LapSRN-master
showIm.m
.m
LapSRN-master/utils/matlabPyrTools/showIm.m
6,111
utf_8
15fbbf55e2fd54e3f48ca936e23c3f32
% RANGE = showIm (MATRIX, RANGE, ZOOM, LABEL, NSHADES ) % % Display a MatLab MATRIX as a grayscale image in the current figure, % inside the current axes. If MATRIX is complex, the real and imaginary % parts are shown side-by-side, with the same grayscale mapping. % % If MATRIX is a string, it should be the name of a variable bound to a % MATRIX in the base (global) environment. This matrix is displayed as an % image, with the title set to the string. % % RANGE (optional) is a 2-vector specifying the values that map to % black and white, respectively. Passing a value of 'auto' (default) % sets RANGE=[min,max] (as in MatLab's imagesc). 'auto2' sets % RANGE=[mean-2*stdev, mean+2*stdev]. 'auto3' sets % RANGE=[p1-(p2-p1)/8, p2+(p2-p1)/8], where p1 is the 10th percentile % value of the sorted MATRIX samples, and p2 is the 90th percentile % value. % % ZOOM specifies the number of matrix samples per screen pixel. It % will be rounded to an integer, or 1 divided by an integer. A value % of 'same' or 'auto' (default) causes the zoom value to be chosen % automatically to fit the image into the current axes. A value of % 'full' fills the axis region (leaving no room for labels). See % pixelAxes.m. % % If LABEL (optional, default = 1, unless zoom='full') is non-zero, the range % of values that are mapped into the gray colormap and the dimensions % (size) of the matrix and zoom factor are printed below the image. If label % is a string, it is used as a title. % % NSHADES (optional) specifies the number of gray shades, and defaults % to the size of the current colormap. % Eero Simoncelli, 6/96. %%TODO: should use "newplot" function range = showIm( im, range, zoom, label, nshades ); %------------------------------------------------------------ %% OPTIONAL ARGS: if (nargin < 1) error('Requires at least one input argument.'); end MLv = version; if isstr(im) if (strcmp(MLv(1),'4')) error('Cannot pass string arg for MATRIX in MatLab version 4.x'); end label = im; im = evalin('base',im); end if (exist('range') ~= 1) range = 'auto1'; end if (exist('nshades') ~= 1) nshades = size(colormap,1); end nshades = max( nshades, 2 ); if (exist('zoom') ~= 1) zoom = 'auto'; end if (exist('label') ~= 1) if strcmp(zoom,'full') label = 0; % no labeling else label = 1; % just print grayrange & dims end end %------------------------------------------------------------ %% Automatic range calculation: if (strcmp(range,'auto1') | strcmp(range,'auto')) if isreal(im) [mn,mx] = range2(im); else [mn1,mx1] = range2(real(im)); [mn2,mx2] = range2(imag(im)); mn = min(mn1,mn2); mx = max(mx1,mx2); end if any(size(im)==1) pad = (mx-mn)/12; % MAGIC NUMBER: graph padding range = [mn-pad, mx+pad]; else range = [mn,mx]; end elseif strcmp(range,'auto2') if isreal(im) stdev = sqrt(var2(im)); av = mean2(im); else stdev = sqrt((var2(real(im)) + var2(imag(im)))/2); av = (mean2(real(im)) + mean2(imag(im)))/2; end range = [av-2*stdev,av+2*stdev]; % MAGIC NUMBER: 2 stdevs elseif strcmp(range, 'auto3') percentile = 0.1; % MAGIC NUMBER: 0<p<0.5 [N,X] = histo(im); binsz = X(2)-X(1); N = N+1e-10; % Ensure cumsum will be monotonic for call to interp1 cumN = [0, cumsum(N)]/sum(N); cumX = [X(1)-binsz, X] + (binsz/2); ctrRange = interp1(cumN,cumX, [percentile, 1-percentile]); range = mean(ctrRange) + (ctrRange-mean(ctrRange))/(1-2*percentile); elseif isstr(range) error(sprintf('Bad RANGE argument: %s',range)) end if ((range(2) - range(1)) <= eps) range(1) = range(1) - 0.5; range(2) = range(2) + 0.5; end if isreal(im) factor=1; else factor = 1+sqrt(-1); end xlbl_offset = 0; % default value if (~any(size(im)==1)) %% MatLab's "image" rounds when mapping to the colormap, so we compute %% (im-r1)*(nshades-1)/(r2-r1) + 1.5 mult = ((nshades-1) / (range(2)-range(1))); d_im = (mult * im) + factor*(1.5 - range(1)*mult); end if isreal(im) if (any(size(im)==1)) hh = plot( im); axis([1, prod(size(im)), range]); else hh = image( d_im ); axis('off'); zoom = pixelAxes(size(d_im),zoom); end else if (any(size(im)==1)) subplot(2,1,1); hh = plot(real(im)); axis([1, prod(size(im)), range]); subplot(2,1,2); hh = plot(imag(im)); axis([1, prod(size(im)), range]); else subplot(1,2,1); hh = image(real(d_im)); axis('off'); zoom = pixelAxes(size(d_im),zoom); ax = gca; orig_units = get(ax,'Units'); set(ax,'Units','points'); pos1 = get(ax,'Position'); set(ax,'Units',orig_units); subplot(1,2,2); hh = image(imag(d_im)); axis('off'); zoom = pixelAxes(size(d_im),zoom); ax = gca; orig_units = get(ax,'Units'); set(ax,'Units','points'); pos2 = get(ax,'Position'); set(ax,'Units',orig_units); xlbl_offset = (pos1(1)-pos2(1))/2; end end if ~any(size(im)==1) colormap(gray(nshades)); end if ((label ~= 0)) if isstr(label) title(label); h = get(gca,'Title'); orig_units = get(h,'Units'); set(h,'Units','points'); pos = get(h,'Position'); pos(1:2) = pos(1:2) + [xlbl_offset, -3]; % MAGIC NUMBER: y pixel offset set(h,'Position',pos); set(h,'Units',orig_units); end if (~any(size(im)==1)) if (zoom > 1) zformat = sprintf('* %d',round(zoom)); else zformat = sprintf('/ %d',round(1/zoom)); end if isreal(im) format=[' Range: [%.3g, %.3g] \n Dims: [%d, %d] ', zformat]; else format=['Range: [%.3g, %.3g] ---- Dims: [%d, %d]', zformat]; end xlabel(sprintf(format, range(1), range(2), size(im,1), size(im,2))); h = get(gca,'Xlabel'); set(h,'FontSize', 9); % MAGIC NUMBER: font size!!! orig_units = get(h,'Units'); set(h,'Units','points'); pos = get(h,'Position'); pos(1:2) = pos(1:2) + [xlbl_offset, 10]; % MAGIC NUMBER: y offset in points set(h,'Position',pos); set(h,'Units',orig_units); set(h,'Visible','on'); % axis('image') turned the xlabel off... end end return;
github
jbhuang0604/LapSRN-master
pyrLow.m
.m
LapSRN-master/utils/matlabPyrTools/pyrLow.m
287
utf_8
b3514ec06e2e106d7b61e534cac20a8e
% RES = pyrLow(PYR, INDICES) % % Access the lowpass subband from a pyramid % (gaussian, laplacian, QMF/wavelet, steerable). % Eero Simoncelli, 6/96. function res = pyrLow(pyr,pind) band = size(pind,1); res = reshape( pyr(pyrBandIndices(pind,band)), pind(band,1), pind(band,2) );
github
jbhuang0604/LapSRN-master
pgmRead.m
.m
LapSRN-master/utils/matlabPyrTools/pgmRead.m
1,259
utf_8
6f07c13cf0f5d8930a46ac0d778bf86f
% IM = pgmRead( FILENAME ) % % Load a pgm image into a MatLab matrix. % This format is accessible from the XV image browsing utility. % Only works for 8bit gray images (raw or ascii) % Hany Farid, Spring '96. Modified by Eero Simoncelli, 6/96. function im = pgmRead( fname ); [fid,msg] = fopen( fname, 'r' ); if (fid == -1) error(msg); end %%% First line contains ID string: %%% "P1" = ascii bitmap, "P2" = ascii greymap, %%% "P3" = ascii pixmap, "P4" = raw bitmap, %%% "P5" = raw greymap, "P6" = raw pixmap TheLine = fgetl(fid); format = TheLine; if ~((format(1:2) == 'P2') | (format(1:2) == 'P5')) error('PGM file must be of type P2 or P5'); end %%% Any number of comment lines TheLine = fgetl(fid); while TheLine(1) == '#' TheLine = fgetl(fid); end %%% dimensions sz = sscanf(TheLine,'%d',2); xdim = sz(1); ydim = sz(2); sz = xdim * ydim; %%% Maximum pixel value TheLine = fgetl(fid); maxval = sscanf(TheLine, '%d',1); %%im = zeros(dim,1); if (format(2) == '2') [im,count] = fscanf(fid,'%d',sz); else [im,count] = fread(fid,sz,'uchar'); end fclose(fid); if (count == sz) im = reshape( im, xdim, ydim )'; else fprintf(1,'Warning: File ended early!'); im = reshape( [im ; zeros(sz-count,1)], xdim, ydim)'; end
github
jbhuang0604/LapSRN-master
upConv.m
.m
LapSRN-master/utils/matlabPyrTools/upConv.m
2,779
utf_8
34137e966f38700416bfb0ebb72663ee
% RES = upConv(IM, FILT, EDGES, STEP, START, STOP, RES) % % Upsample matrix IM, followed by convolution with matrix FILT. These % arguments should be 1D or 2D matrices, and IM must be larger (in % both dimensions) than FILT. The origin of filt % is assumed to be floor(size(filt)/2)+1. % % EDGES is a string determining boundary handling: % 'circular' - Circular convolution % 'reflect1' - Reflect about the edge pixels % 'reflect2' - Reflect, doubling the edge pixels % 'repeat' - Repeat the edge pixels % 'zero' - Assume values of zero outside image boundary % 'extend' - Reflect and invert % 'dont-compute' - Zero output when filter overhangs OUTPUT boundaries % % Upsampling factors are determined by STEP (optional, default=[1 1]), % a 2-vector [y,x]. % % The window over which the convolution occurs is specfied by START % (optional, default=[1,1], and STOP (optional, default = % step .* (size(IM) + floor((start-1)./step))). % % RES is an optional result matrix. The convolution result will be % destructively added into this matrix. If this argument is passed, the % result matrix will not be returned. DO NOT USE THIS ARGUMENT IF % YOU DO NOT UNDERSTAND WHAT THIS MEANS!! % % NOTE: this operation corresponds to multiplication of a signal % vector by a matrix whose columns contain copies of the time-reversed % (or space-reversed) FILT shifted by multiples of STEP. See corrDn.m % for the operation corresponding to the transpose of this matrix. % Eero Simoncelli, 6/96. revised 2/97. function result = upConv(im,filt,edges,step,start,stop,res) %% THIS CODE IS NOT ACTUALLY USED! (MEX FILE IS CALLED INSTEAD) fprintf(1,'WARNING: You should compile the MEX version of "upConv.c",\n found in the MEX subdirectory of matlabPyrTools, and put it in your matlab path. It is MUCH faster, and provides more boundary-handling options.\n'); %------------------------------------------------------------ %% OPTIONAL ARGS: if (exist('edges') == 1) if (strcmp(edges,'reflect1') ~= 1) warning('Using REFLECT1 edge-handling (use MEX code for other options).'); end end if (exist('step') ~= 1) step = [1,1]; end if (exist('start') ~= 1) start = [1,1]; end % A multiple of step if (exist('stop') ~= 1) stop = step .* (floor((start-ones(size(start)))./step)+size(im)) end if ( ceil((stop(1)+1-start(1)) / step(1)) ~= size(im,1) ) error('Bad Y result dimension'); end if ( ceil((stop(2)+1-start(2)) / step(2)) ~= size(im,2) ) error('Bad X result dimension'); end if (exist('res') ~= 1) res = zeros(stop-start+1); end %------------------------------------------------------------ tmp = zeros(size(res)); tmp(start(1):step(1):stop(1),start(2):step(2):stop(2)) = im; result = rconv2(tmp,filt) + res;
github
jbhuang0604/LapSRN-master
mean2.m
.m
LapSRN-master/utils/matlabPyrTools/mean2.m
97
utf_8
cacc007ef6e32ba40a1e0da3b3d80a0e
% M = MEAN2(MTX) % % Sample mean of a matrix. function res = mean2(mtx) res = mean(mean(mtx));
github
jbhuang0604/LapSRN-master
range2.m
.m
LapSRN-master/utils/matlabPyrTools/range2.m
523
utf_8
b9f23c3a4f73bf568a1b5793f516aa80
% [MIN, MAX] = range2(MTX) % % Compute minimum and maximum values of MTX, returning them as a 2-vector. % Eero Simoncelli, 3/97. function [mn, mx] = range2(mtx) %% NOTE: THIS CODE IS NOT ACTUALLY USED! (MEX FILE IS CALLED INSTEAD) fprintf(1,'WARNING: You should compile the MEX version of "range2.c",\n found in the MEX subdirectory of matlabPyrTools, and put it in your matlab path. It is MUCH faster.\n'); if (~isreal(mtx)) error('MTX must be real-valued'); end mn = min(min(mtx)); mx = max(max(mtx));
github
jbhuang0604/LapSRN-master
buildSCFpyrLevs.m
.m
LapSRN-master/utils/matlabPyrTools/buildSCFpyrLevs.m
2,187
utf_8
26747285064a0eaa2f3db75013e80849
% [PYR, INDICES] = buildSCFpyrLevs(LODFT, LOGRAD, XRCOS, YRCOS, ANGLE, HEIGHT, NBANDS) % % Recursive function for constructing levels of a steerable pyramid. This % is called by buildSCFpyr, and is not usually called directly. % Original code: Eero Simoncelli, 5/97. % Modified by Javier Portilla to generate complex bands in 9/97. function [pyr,pind] = buildSCFpyrLevs(lodft,log_rad,Xrcos,Yrcos,angle,ht,nbands); if (ht <= 0) lo0 = ifft2(ifftshift(lodft)); pyr = real(lo0(:)); pind = size(lo0); else bands = zeros(prod(size(lodft)), nbands); bind = zeros(nbands,2); % log_rad = log_rad + 1; Xrcos = Xrcos - log2(2); % shift origin of lut by 1 octave. lutsize = 1024; Xcosn = pi*[-(2*lutsize+1):(lutsize+1)]/lutsize; % [-2*pi:pi] order = nbands-1; %% divide by sqrt(sum_(n=0)^(N-1) cos(pi*n/N)^(2(N-1)) ) %% Thanks to Patrick Teo for writing this out :) const = (2^(2*order))*(factorial(order)^2)/(nbands*factorial(2*order)); % % Ycosn = sqrt(const) * (cos(Xcosn)).^order; % % analityc version: only take one lobe alfa= mod(pi+Xcosn,2*pi)-pi; Ycosn = 2*sqrt(const) * (cos(Xcosn).^order) .* (abs(alfa)<pi/2); himask = pointOp(log_rad, Yrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0); for b = 1:nbands anglemask = pointOp(angle, Ycosn, Xcosn(1)+pi*(b-1)/nbands, Xcosn(2)-Xcosn(1)); banddft = ((-i)^(nbands-1)) .* lodft .* anglemask .* himask; band = ifft2(ifftshift(banddft)); % bands(:,b) = real(band(:)); % analytic version: full complex value bands(:,b)=band(:); bind(b,:) = size(band); end dims = size(lodft); ctr = ceil((dims+0.5)/2); lodims = ceil((dims-0.5)/2); loctr = ceil((lodims+0.5)/2); lostart = ctr-loctr+1; loend = lostart+lodims-1; log_rad = log_rad(lostart(1):loend(1),lostart(2):loend(2)); angle = angle(lostart(1):loend(1),lostart(2):loend(2)); lodft = lodft(lostart(1):loend(1),lostart(2):loend(2)); YIrcos = abs(sqrt(1.0 - Yrcos.^2)); lomask = pointOp(log_rad, YIrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0); lodft = lomask .* lodft; [npyr,nind] = buildSCFpyrLevs(lodft, log_rad, Xrcos, Yrcos, angle, ht-1, nbands); pyr = [bands(:); npyr]; pind = [bind; nind]; end
github
jbhuang0604/LapSRN-master
clip.m
.m
LapSRN-master/utils/matlabPyrTools/clip.m
814
utf_8
13c82937ba69d5bc8c94b2ccca783e1b
% [RES] = clip(IM, MINVALorRANGE, MAXVAL) % % Clip values of matrix IM to lie between minVal and maxVal: % RES = max(min(IM,MAXVAL),MINVAL) % The first argument can also specify both min and max, as a 2-vector. % If only one argument is passed, the range defaults to [0,1]. function res = clip(im, minValOrRange, maxVal) if (exist('minValOrRange') ~= 1) minVal = 0; maxVal = 1; elseif (length(minValOrRange) == 2) minVal = minValOrRange(1); maxVal = minValOrRange(2); elseif (length(minValOrRange) == 1) minVal = minValOrRange; if (exist('maxVal') ~= 1) maxVal=minVal+1; end else error('MINVAL must be a scalar or a 2-vector'); end if ( maxVal < minVal ) error('MAXVAL should be less than MINVAL'); end res = im; res(find(im < minVal)) = minVal; res(find(im > maxVal)) = maxVal;
github
jbhuang0604/LapSRN-master
upBlur.m
.m
LapSRN-master/utils/matlabPyrTools/upBlur.m
1,213
utf_8
7b07d26940520537edb6e8dc25b72242
% RES = upBlur(IM, LEVELS, FILT) % % Upsample and blur an image. The blurring is done with filter % kernel specified by FILT (default = 'binom5'), which can be a string % (to be passed to namedFilter), a vector (applied separably as a 1D % convolution kernel in X and Y), or a matrix (applied as a 2D % convolution kernel). The downsampling is always by 2 in each % direction. % % The procedure is applied recursively LEVELS times (default=1). % Eero Simoncelli, 4/97. function res = upBlur(im, nlevs, filt) %------------------------------------------------------------ %% OPTIONAL ARGS: if (exist('nlevs') ~= 1) nlevs = 1; end if (exist('filt') ~= 1) filt = 'binom5'; end %------------------------------------------------------------ if isstr(filt) filt = namedFilter(filt); end if nlevs > 1 im = upBlur(im,nlevs-1,filt); end if (nlevs >= 1) if (any(size(im)==1)) if (size(im,1)==1) filt = filt'; end res = upConv(im,filt,'reflect1',(size(im)~=1)+1); elseif (any(size(filt)==1)) filt = filt(:); res = upConv(im,filt,'reflect1',[2 1]); res = upConv(res,filt','reflect1',[1 2]); else res = upConv(im,filt,'reflect1',[2 2]); end else res = im; end
github
jbhuang0604/LapSRN-master
nextFig.m
.m
LapSRN-master/utils/matlabPyrTools/nextFig.m
363
utf_8
94a66b00983cd3840ff1cc88f118a022
% nextFig (MAXFIGS, SKIP) % % Make figure number mod((GCF+SKIP), MAXFIGS) the current figure. % MAXFIGS is optional, and defaults to 2. % SKIP is optional, and defaults to 1. % Eero Simoncelli, 2/97. function nextFig(maxfigs, skip) if (exist('maxfigs') ~= 1) maxfigs = 2; end if (exist('skip') ~= 1) skip = 1; end figure(1+mod(gcf-1+skip,maxfigs));
github
jbhuang0604/LapSRN-master
zconv2.m
.m
LapSRN-master/utils/matlabPyrTools/zconv2.m
1,164
utf_8
cd266795530db4cb146c1038383316f3
% RES = ZCONV2(MTX1, MTX2, CTR) % % Convolution of two matrices, with boundaries handled as if the larger mtx % lies in a sea of zeros. Result will be of size of LARGER vector. % % The origin of the smaller matrix is assumed to be its center. % For even dimensions, the origin is determined by the CTR (optional) % argument: % CTR origin % 0 DIM/2 (default) % 1 (DIM/2)+1 (behaves like conv2(mtx1,mtx2,'same')) % Eero Simoncelli, 2/97. function c = zconv2(a,b,ctr) if (exist('ctr') ~= 1) ctr = 0; end if (( size(a,1) >= size(b,1) ) & ( size(a,2) >= size(b,2) )) large = a; small = b; elseif (( size(a,1) <= size(b,1) ) & ( size(a,2) <= size(b,2) )) large = b; small = a; else error('one arg must be larger than the other in both dimensions!'); end ly = size(large,1); lx = size(large,2); sy = size(small,1); sx = size(small,2); %% These values are the index of the small mtx that falls on the %% border pixel of the large matrix when computing the first %% convolution response sample: sy2 = floor((sy+ctr+1)/2); sx2 = floor((sx+ctr+1)/2); clarge = conv2(large,small); c = clarge(sy2:ly+sy2-1, sx2:lx+sx2-1);
github
jbhuang0604/LapSRN-master
mkZonePlate.m
.m
LapSRN-master/utils/matlabPyrTools/mkZonePlate.m
633
utf_8
d88329c8d374e54e124222c825679768
% IM = mkZonePlate(SIZE, AMPL, PHASE) % % Make a "zone plate" image: % AMPL * cos( r^2 + PHASE) % SIZE specifies the matrix size, as for zeros(). % AMPL (default = 1) and PHASE (default = 0) are optional. % Eero Simoncelli, 6/96. function [res] = mkZonePlate(sz, ampl, ph) sz = sz(:); if (size(sz,1) == 1) sz = [sz,sz]; end mxsz = max(sz(1),sz(2)); %------------------------------------------------------------ %% OPTIONAL ARGS: if (exist('ampl') ~= 1) ampl = 1; end if (exist('ph') ~= 1) ph = 0; end %------------------------------------------------------------ res = ampl * cos( (pi/mxsz) * mkR(sz,2) + ph );
github
jbhuang0604/LapSRN-master
steer2HarmMtx.m
.m
LapSRN-master/utils/matlabPyrTools/steer2HarmMtx.m
1,803
utf_8
35816be985c308717168260dc97419d8
% MTX = steer2HarmMtx(HARMONICS, ANGLES, REL_PHASES) % % Compute a steering matrix (maps a directional basis set onto the % angular Fourier harmonics). HARMONICS is a vector specifying the % angular harmonics contained in the steerable basis/filters. ANGLES % (optional) is a vector specifying the angular position of each filter. % REL_PHASES (optional, default = 'even') specifies whether the harmonics % are cosine or sine phase aligned about those positions. % The result matrix is suitable for passing to the function STEER. % Eero Simoncelli, 7/96. function mtx = steer2HarmMtx(harmonics, angles, evenorodd) %%================================================================= %%% Optional Parameters: if (exist('evenorodd') ~= 1) evenorodd = 'even'; end % Make HARMONICS a row vector harmonics = harmonics(:)'; numh = 2*size(harmonics,2) - any(harmonics == 0); if (exist('angles') ~= 1) angles = pi * [0:numh-1]'/numh; else angles = angles(:); end %%================================================================= if isstr(evenorodd) if strcmp(evenorodd,'even') evenorodd = 0; elseif strcmp(evenorodd,'odd') evenorodd = 1; else error('EVEN_OR_ODD should be the string EVEN or ODD'); end end %% Compute inverse matrix, which maps Fourier components onto %% steerable basis. imtx = zeros(size(angles,1),numh); col = 1; for h=harmonics args = h*angles; if (h == 0) imtx(:,col) = ones(size(angles)); col = col+1; elseif evenorodd imtx(:,col) = sin(args); imtx(:,col+1) = -cos(args); col = col+2; else imtx(:,col) = cos(args); imtx(:,col+1) = sin(args); col = col+2; end end r = rank(imtx); if (( r ~= numh ) & ( r ~= size(angles,1) )) fprintf(2,'WARNING: matrix is not full rank'); end mtx = pinv(imtx);
github
jbhuang0604/LapSRN-master
mkAngularSine.m
.m
LapSRN-master/utils/matlabPyrTools/mkAngularSine.m
845
utf_8
78a5e0afe3fef5c42804516e2ea1ccc8
% IM = mkAngularSine(SIZE, HARMONIC, AMPL, PHASE, ORIGIN) % % Make an angular sinusoidal image: % AMPL * sin( HARMONIC*theta + PHASE), % where theta is the angle about the origin. % SIZE specifies the matrix size, as for zeros(). % AMPL (default = 1) and PHASE (default = 0) are optional. % Eero Simoncelli, 2/97. function [res] = mkAngularSine(sz, harmonic, ampl, ph, origin) sz = sz(:); if (size(sz,1) == 1) sz = [sz,sz]; end mxsz = max(sz(1),sz(2)); %------------------------------------------------------------ %% OPTIONAL ARGS: if (exist('harmonic') ~= 1) harmonic = 1; end if (exist('ampl') ~= 1) ampl = 1; end if (exist('ph') ~= 1) ph = 0; end if (exist('origin') ~= 1) origin = (sz+1)/2; end %------------------------------------------------------------ res = ampl * sin(harmonic*mkAngle(sz,ph,origin) + ph);
github
jbhuang0604/LapSRN-master
mkRamp.m
.m
LapSRN-master/utils/matlabPyrTools/mkRamp.m
1,110
utf_8
28989822e19c604a816a287a4bee873d
% IM = mkRamp(SIZE, DIRECTION, SLOPE, INTERCEPT, ORIGIN) % % Compute a matrix of dimension SIZE (a [Y X] 2-vector, or a scalar) % containing samples of a ramp function, with given gradient DIRECTION % (radians, CW from X-axis, default = 0), SLOPE (per pixel, default = % 1), and a value of INTERCEPT (default = 0) at the ORIGIN (default = % (size+1)/2, [1 1] = upper left). All but the first argument are % optional. % Eero Simoncelli, 6/96. 2/97: adjusted coordinate system. function [res] = mkRamp(sz, dir, slope, intercept, origin) sz = sz(:); if (size(sz,1) == 1) sz = [sz,sz]; end % ----------------------------------------------------------------- % OPTIONAL args: if (exist('dir') ~= 1) dir = 0; end if (exist('slope') ~= 1) slope = 1; end if (exist('intercept') ~= 1) intercept = 0; end if (exist('origin') ~= 1) origin = (sz+1)/2; end % ----------------------------------------------------------------- xinc = slope*cos(dir); yinc = slope*sin(dir); [xramp,yramp] = meshgrid( xinc*([1:sz(2)]-origin(2)), ... yinc*([1:sz(1)]-origin(1)) ); res = intercept + xramp + yramp;
github
jbhuang0604/LapSRN-master
histoMatch.m
.m
LapSRN-master/utils/matlabPyrTools/histoMatch.m
858
utf_8
8936fc2eadacc591ecdffe5967726780
% RES = histoMatch(MTX, N, X) % % Modify elements of MTX so that normalized histogram matches that % specified by vectors X and N, where N contains the histogram counts % and X the histogram bin positions (see histo). % Eero Simoncelli, 7/96. function res = histoMatch(mtx, N, X) if ( exist('histo') == 3 ) [oN, oX] = histo(mtx(:), size(X(:),1)); else [oN, oX] = hist(mtx(:), size(X(:),1)); end oStep = oX(2) - oX(1); oC = [0, cumsum(oN)]/sum(oN); oX = [oX(1)-oStep/2, oX+oStep/2]; N = N(:)'; X = X(:)'; N = N + mean(N)/(1e8); %% HACK: no empty bins ensures nC strictly monotonic nStep = X(2) - X(1); nC = [0, cumsum(N)]/sum(N); nX = [X(1)-nStep/2, X+nStep/2]; nnX = interp1(nC, nX, oC, 'linear'); if ( exist('pointOp') == 3 ) res = pointOp(mtx, nnX, oX(1), oStep); else res = reshape(interp1(oX, nnX, mtx(:)),size(mtx,1),size(mtx,2)); end
github
jbhuang0604/LapSRN-master
subMtx.m
.m
LapSRN-master/utils/matlabPyrTools/subMtx.m
420
utf_8
c660029ce728dcb8c540c9cf419fa7bc
% MTX = subMtx(VEC, DIMENSIONS, START_INDEX) % % Reshape a portion of VEC starting from START_INDEX (optional, % default=1) to the given dimensions. % Eero Simoncelli, 6/96. function mtx = subMtx(vec, sz, offset) if (exist('offset') ~= 1) offset = 1; end vec = vec(:); sz = sz(:); if (size(sz,1) ~= 2) error('DIMENSIONS must be a 2-vector.'); end mtx = reshape( vec(offset:offset+prod(sz)-1), sz(1), sz(2) );
github
jbhuang0604/LapSRN-master
showLpyr.m
.m
LapSRN-master/utils/matlabPyrTools/showLpyr.m
5,421
utf_8
0646b94ae144cf6160a44f50e67f8dd5
% RANGE = showLpyr (PYR, INDICES, RANGE, GAP, LEVEL_SCALE_FACTOR) % % Display a Laplacian (or Gaussian) pyramid, specified by PYR and % INDICES (see buildLpyr), in the current figure. % % RANGE is a 2-vector specifying the values that map to black and % white, respectively. These values are scaled by % LEVEL_SCALE_FACTOR^(lev-1) for bands at each level. Passing a value % of 'auto1' sets RANGE to the min and max values of MATRIX. 'auto2' % sets RANGE to 3 standard deviations below and above 0.0. In both of % these cases, the lowpass band is independently scaled. A value of % 'indep1' sets the range of each subband independently, as in a call % to showIm(subband,'auto1'). Similarly, 'indep2' causes each subband % to be scaled independently as if by showIm(subband,'indep2'). % The default value for RANGE is 'auto1' for 1D images, and 'auto2' for % 2D images. % % GAP (optional, default=1) specifies the gap in pixels to leave % between subbands (2D images only). % % LEVEL_SCALE_FACTOR indicates the relative scaling between pyramid % levels. This should be set to the sum of the kernel taps of the % lowpass filter used to construct the pyramid (default assumes % L2-normalalized filters, using a value of 2 for 2D images, sqrt(2) for % 1D images). % Eero Simoncelli, 2/97. function [range] = showLpyr(pyr, pind, range, gap, scale); % Determine 1D or 2D pyramid: if ((pind(1,1) == 1) | (pind(1,2) ==1)) oned = 1; else oned = 0; end %------------------------------------------------------------ %% OPTIONAL ARGS: if (exist('range') ~= 1) if (oned==1) range = 'auto1'; else range = 'auto2'; end end if (exist('gap') ~= 1) gap = 1; end if (exist('scale') ~= 1) if (oned == 1) scale = sqrt(2); else scale = 2; end end %------------------------------------------------------------ nind = size(pind,1); %% Auto range calculations: if strcmp(range,'auto1') range = zeros(nind,1); mn = 0.0; mx = 0.0; for bnum = 1:(nind-1) band = pyrBand(pyr,pind,bnum)/(scale^(bnum-1)); range(bnum) = scale^(bnum-1); [bmn,bmx] = range2(band); mn = min(mn, bmn); mx = max(mx, bmx); end if (oned == 1) pad = (mx-mn)/12; % *** MAGIC NUMBER!! mn = mn-pad; mx = mx+pad; end range = range * [mn mx]; % outer product band = pyrLow(pyr,pind); [mn,mx] = range2(band); if (oned == 1) pad = (mx-mn)/12; % *** MAGIC NUMBER!! mn = mn-pad; mx = mx+pad; end range(nind,:) = [mn, mx]; elseif strcmp(range,'indep1') range = zeros(nind,2); for bnum = 1:nind band = pyrBand(pyr,pind,bnum); [mn,mx] = range2(band); if (oned == 1) pad = (mx-mn)/12; % *** MAGIC NUMBER!! mn = mn-pad; mx = mx+pad; end range(bnum,:) = [mn mx]; end elseif strcmp(range,'auto2') range = zeros(nind,1); sqsum = 0; numpixels = 0; for bnum = 1:(nind-1) band = pyrBand(pyr,pind,bnum)/(scale^(bnum-1)); sqsum = sqsum + sum(sum(band.^2)); numpixels = numpixels + prod(size(band)); range(bnum) = scale^(bnum-1); end stdev = sqrt(sqsum/(numpixels-1)); range = range * [ -3*stdev 3*stdev ]; % outer product band = pyrLow(pyr,pind); av = mean2(band); stdev = sqrt(var2(band)); range(nind,:) = [av-2*stdev,av+2*stdev]; elseif strcmp(range,'indep2') range = zeros(nind,2); for bnum = 1:(nind-1) band = pyrBand(pyr,pind,bnum); stdev = sqrt(var2(band)); range(bnum,:) = [ -3*stdev 3*stdev ]; end band = pyrLow(pyr,pind); av = mean2(band); stdev = sqrt(var2(band)); range(nind,:) = [av-2*stdev,av+2*stdev]; elseif isstr(range) error(sprintf('Bad RANGE argument: %s',range)) elseif ((size(range,1) == 1) & (size(range,2) == 2)) scales = scale.^[0:nind-1]; range = scales(:) * range; % outer product band = pyrLow(pyr,pind); range(nind,:) = range(nind,:) + mean2(band) - mean(range(nind,:)); end %% Clear Figure clf; if (oned == 1) %%%%% 1D signal: for bnum=1:nind band = pyrBand(pyr,pind,bnum); subplot(nind,1,nind-bnum+1); plot(band); axis([1, prod(size(band)), range(bnum,:)]); end else %%%%% 2D signal: colormap(gray); cmap = get(gcf,'Colormap'); nshades = size(cmap,1); % Find background color index: clr = get(gcf,'Color'); bg = 1; dist = norm(cmap(bg,:)-clr); for n = 1:nshades ndist = norm(cmap(n,:)-clr); if (ndist < dist) dist = ndist; bg = n; end end %% Compute positions of subbands: llpos = ones(nind,2); dir = [-1 -1]; ctr = [pind(1,1)+1+gap 1]; sz = [0 0]; for bnum = 1:nind prevsz = sz; sz = pind(bnum,:); % Determine center position of new band: ctr = ctr + gap*dir/2 + dir.* floor((prevsz+(dir>0))/2); dir = dir * [0 -1; 1 0]; % ccw rotation ctr = ctr + gap*dir/2 + dir.* floor((sz+(dir<0))/2); llpos(bnum,:) = ctr - floor(sz./2); end %% Make position list positive, and allocate appropriate image: llpos = llpos - ones(nind,1)*min(llpos) + 1; urpos = llpos + pind - 1; d_im = bg + zeros(max(urpos)); %% Paste bands into image, (im-r1)*(nshades-1)/(r2-r1) + 1.5 for bnum=1:nind mult = (nshades-1) / (range(bnum,2)-range(bnum,1)); d_im(llpos(bnum,1):urpos(bnum,1), llpos(bnum,2):urpos(bnum,2)) = ... mult*pyrBand(pyr,pind,bnum) + (1.5-mult*range(bnum,1)); end hh = image(d_im); axis('off'); pixelAxes(size(d_im),'full'); set(hh,'UserData',range); end
github
jbhuang0604/LapSRN-master
sp1Filters.m
.m
LapSRN-master/utils/matlabPyrTools/sp1Filters.m
9,435
utf_8
81cfbf726744492bee2374b9b564ebdf
% Steerable pyramid filters. Transform described in: % % @INPROCEEDINGS{Simoncelli95b, % TITLE = "The Steerable Pyramid: A Flexible Architecture for % Multi-Scale Derivative Computation", % AUTHOR = "E P Simoncelli and W T Freeman", % BOOKTITLE = "Second Int'l Conf on Image Processing", % ADDRESS = "Washington, DC", MONTH = "October", YEAR = 1995 } % % Filter kernel design described in: % %@INPROCEEDINGS{Karasaridis96, % TITLE = "A Filter Design Technique for % Steerable Pyramid Image Transforms", % AUTHOR = "A Karasaridis and E P Simoncelli", % BOOKTITLE = "ICASSP", ADDRESS = "Atlanta, GA", % MONTH = "May", YEAR = 1996 } % Eero Simoncelli, 6/96. function [lo0filt,hi0filt,lofilt,bfilts,mtx,harmonics] = sp1Filters(); harmonics = [ 1 ]; %% filters only contain first harmonic. mtx = eye(2); lo0filt = [ ... -8.701000e-05 -1.354280e-03 -1.601260e-03 -5.033700e-04 2.524010e-03 -5.033700e-04 -1.601260e-03 -1.354280e-03 -8.701000e-05 -1.354280e-03 2.921580e-03 7.522720e-03 8.224420e-03 1.107620e-03 8.224420e-03 7.522720e-03 2.921580e-03 -1.354280e-03 -1.601260e-03 7.522720e-03 -7.061290e-03 -3.769487e-02 -3.297137e-02 -3.769487e-02 -7.061290e-03 7.522720e-03 -1.601260e-03 -5.033700e-04 8.224420e-03 -3.769487e-02 4.381320e-02 1.811603e-01 4.381320e-02 -3.769487e-02 8.224420e-03 -5.033700e-04 2.524010e-03 1.107620e-03 -3.297137e-02 1.811603e-01 4.376250e-01 1.811603e-01 -3.297137e-02 1.107620e-03 2.524010e-03 -5.033700e-04 8.224420e-03 -3.769487e-02 4.381320e-02 1.811603e-01 4.381320e-02 -3.769487e-02 8.224420e-03 -5.033700e-04 -1.601260e-03 7.522720e-03 -7.061290e-03 -3.769487e-02 -3.297137e-02 -3.769487e-02 -7.061290e-03 7.522720e-03 -1.601260e-03 -1.354280e-03 2.921580e-03 7.522720e-03 8.224420e-03 1.107620e-03 8.224420e-03 7.522720e-03 2.921580e-03 -1.354280e-03 -8.701000e-05 -1.354280e-03 -1.601260e-03 -5.033700e-04 2.524010e-03 -5.033700e-04 -1.601260e-03 -1.354280e-03 -8.701000e-05 ]; lofilt = [ ... -4.350000e-05 1.207800e-04 -6.771400e-04 -1.243400e-04 -8.006400e-04 -1.597040e-03 -2.516800e-04 -4.202000e-04 1.262000e-03 -4.202000e-04 -2.516800e-04 -1.597040e-03 -8.006400e-04 -1.243400e-04 -6.771400e-04 1.207800e-04 -4.350000e-05 ; ... 1.207800e-04 4.460600e-04 -5.814600e-04 5.621600e-04 -1.368800e-04 2.325540e-03 2.889860e-03 4.287280e-03 5.589400e-03 4.287280e-03 2.889860e-03 2.325540e-03 -1.368800e-04 5.621600e-04 -5.814600e-04 4.460600e-04 1.207800e-04 ; ... -6.771400e-04 -5.814600e-04 1.460780e-03 2.160540e-03 3.761360e-03 3.080980e-03 4.112200e-03 2.221220e-03 5.538200e-04 2.221220e-03 4.112200e-03 3.080980e-03 3.761360e-03 2.160540e-03 1.460780e-03 -5.814600e-04 -6.771400e-04 ; ... -1.243400e-04 5.621600e-04 2.160540e-03 3.175780e-03 3.184680e-03 -1.777480e-03 -7.431700e-03 -9.056920e-03 -9.637220e-03 -9.056920e-03 -7.431700e-03 -1.777480e-03 3.184680e-03 3.175780e-03 2.160540e-03 5.621600e-04 -1.243400e-04 ; ... -8.006400e-04 -1.368800e-04 3.761360e-03 3.184680e-03 -3.530640e-03 -1.260420e-02 -1.884744e-02 -1.750818e-02 -1.648568e-02 -1.750818e-02 -1.884744e-02 -1.260420e-02 -3.530640e-03 3.184680e-03 3.761360e-03 -1.368800e-04 -8.006400e-04 ; ... -1.597040e-03 2.325540e-03 3.080980e-03 -1.777480e-03 -1.260420e-02 -2.022938e-02 -1.109170e-02 3.955660e-03 1.438512e-02 3.955660e-03 -1.109170e-02 -2.022938e-02 -1.260420e-02 -1.777480e-03 3.080980e-03 2.325540e-03 -1.597040e-03 ; ... -2.516800e-04 2.889860e-03 4.112200e-03 -7.431700e-03 -1.884744e-02 -1.109170e-02 2.190660e-02 6.806584e-02 9.058014e-02 6.806584e-02 2.190660e-02 -1.109170e-02 -1.884744e-02 -7.431700e-03 4.112200e-03 2.889860e-03 -2.516800e-04 ; ... -4.202000e-04 4.287280e-03 2.221220e-03 -9.056920e-03 -1.750818e-02 3.955660e-03 6.806584e-02 1.445500e-01 1.773651e-01 1.445500e-01 6.806584e-02 3.955660e-03 -1.750818e-02 -9.056920e-03 2.221220e-03 4.287280e-03 -4.202000e-04 ; ... 1.262000e-03 5.589400e-03 5.538200e-04 -9.637220e-03 -1.648568e-02 1.438512e-02 9.058014e-02 1.773651e-01 2.120374e-01 1.773651e-01 9.058014e-02 1.438512e-02 -1.648568e-02 -9.637220e-03 5.538200e-04 5.589400e-03 1.262000e-03 ; ... -4.202000e-04 4.287280e-03 2.221220e-03 -9.056920e-03 -1.750818e-02 3.955660e-03 6.806584e-02 1.445500e-01 1.773651e-01 1.445500e-01 6.806584e-02 3.955660e-03 -1.750818e-02 -9.056920e-03 2.221220e-03 4.287280e-03 -4.202000e-04 ; ... -2.516800e-04 2.889860e-03 4.112200e-03 -7.431700e-03 -1.884744e-02 -1.109170e-02 2.190660e-02 6.806584e-02 9.058014e-02 6.806584e-02 2.190660e-02 -1.109170e-02 -1.884744e-02 -7.431700e-03 4.112200e-03 2.889860e-03 -2.516800e-04 ; ... -1.597040e-03 2.325540e-03 3.080980e-03 -1.777480e-03 -1.260420e-02 -2.022938e-02 -1.109170e-02 3.955660e-03 1.438512e-02 3.955660e-03 -1.109170e-02 -2.022938e-02 -1.260420e-02 -1.777480e-03 3.080980e-03 2.325540e-03 -1.597040e-03 ; ... -8.006400e-04 -1.368800e-04 3.761360e-03 3.184680e-03 -3.530640e-03 -1.260420e-02 -1.884744e-02 -1.750818e-02 -1.648568e-02 -1.750818e-02 -1.884744e-02 -1.260420e-02 -3.530640e-03 3.184680e-03 3.761360e-03 -1.368800e-04 -8.006400e-04 ; ... -1.243400e-04 5.621600e-04 2.160540e-03 3.175780e-03 3.184680e-03 -1.777480e-03 -7.431700e-03 -9.056920e-03 -9.637220e-03 -9.056920e-03 -7.431700e-03 -1.777480e-03 3.184680e-03 3.175780e-03 2.160540e-03 5.621600e-04 -1.243400e-04 ; ... -6.771400e-04 -5.814600e-04 1.460780e-03 2.160540e-03 3.761360e-03 3.080980e-03 4.112200e-03 2.221220e-03 5.538200e-04 2.221220e-03 4.112200e-03 3.080980e-03 3.761360e-03 2.160540e-03 1.460780e-03 -5.814600e-04 -6.771400e-04 ; ... 1.207800e-04 4.460600e-04 -5.814600e-04 5.621600e-04 -1.368800e-04 2.325540e-03 2.889860e-03 4.287280e-03 5.589400e-03 4.287280e-03 2.889860e-03 2.325540e-03 -1.368800e-04 5.621600e-04 -5.814600e-04 4.460600e-04 1.207800e-04 ; ... -4.350000e-05 1.207800e-04 -6.771400e-04 -1.243400e-04 -8.006400e-04 -1.597040e-03 -2.516800e-04 -4.202000e-04 1.262000e-03 -4.202000e-04 -2.516800e-04 -1.597040e-03 -8.006400e-04 -1.243400e-04 -6.771400e-04 1.207800e-04 -4.350000e-05 ]; hi0filt = [... -9.570000e-04 -2.424100e-04 -1.424720e-03 -8.742600e-04 -1.166810e-03 -8.742600e-04 -1.424720e-03 -2.424100e-04 -9.570000e-04 ; ... -2.424100e-04 -4.317530e-03 8.998600e-04 9.156420e-03 1.098012e-02 9.156420e-03 8.998600e-04 -4.317530e-03 -2.424100e-04 ; ... -1.424720e-03 8.998600e-04 1.706347e-02 1.094866e-02 -5.897780e-03 1.094866e-02 1.706347e-02 8.998600e-04 -1.424720e-03 ; ... -8.742600e-04 9.156420e-03 1.094866e-02 -7.841370e-02 -1.562827e-01 -7.841370e-02 1.094866e-02 9.156420e-03 -8.742600e-04 ; ... -1.166810e-03 1.098012e-02 -5.897780e-03 -1.562827e-01 7.282593e-01 -1.562827e-01 -5.897780e-03 1.098012e-02 -1.166810e-03 ; ... -8.742600e-04 9.156420e-03 1.094866e-02 -7.841370e-02 -1.562827e-01 -7.841370e-02 1.094866e-02 9.156420e-03 -8.742600e-04 ; ... -1.424720e-03 8.998600e-04 1.706347e-02 1.094866e-02 -5.897780e-03 1.094866e-02 1.706347e-02 8.998600e-04 -1.424720e-03 ; ... -2.424100e-04 -4.317530e-03 8.998600e-04 9.156420e-03 1.098012e-02 9.156420e-03 8.998600e-04 -4.317530e-03 -2.424100e-04 ; ... -9.570000e-04 -2.424100e-04 -1.424720e-03 -8.742600e-04 -1.166810e-03 -8.742600e-04 -1.424720e-03 -2.424100e-04 -9.570000e-04 ]; bfilts = -[ ... 6.125880e-03 -8.052600e-03 -2.103714e-02 -1.536890e-02 -1.851466e-02 -1.536890e-02 -2.103714e-02 -8.052600e-03 6.125880e-03 ... -1.287416e-02 -9.611520e-03 1.023569e-02 6.009450e-03 1.872620e-03 6.009450e-03 1.023569e-02 -9.611520e-03 -1.287416e-02 ... -5.641530e-03 4.168400e-03 -2.382180e-02 -5.375324e-02 -2.076086e-02 -5.375324e-02 -2.382180e-02 4.168400e-03 -5.641530e-03 ... -8.957260e-03 -1.751170e-03 -1.836909e-02 1.265655e-01 2.996168e-01 1.265655e-01 -1.836909e-02 -1.751170e-03 -8.957260e-03 ... 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 ... 8.957260e-03 1.751170e-03 1.836909e-02 -1.265655e-01 -2.996168e-01 -1.265655e-01 1.836909e-02 1.751170e-03 8.957260e-03 ... 5.641530e-03 -4.168400e-03 2.382180e-02 5.375324e-02 2.076086e-02 5.375324e-02 2.382180e-02 -4.168400e-03 5.641530e-03 ... 1.287416e-02 9.611520e-03 -1.023569e-02 -6.009450e-03 -1.872620e-03 -6.009450e-03 -1.023569e-02 9.611520e-03 1.287416e-02 ... -6.125880e-03 8.052600e-03 2.103714e-02 1.536890e-02 1.851466e-02 1.536890e-02 2.103714e-02 8.052600e-03 -6.125880e-03; ... ... -6.125880e-03 1.287416e-02 5.641530e-03 8.957260e-03 0.000000e+00 -8.957260e-03 -5.641530e-03 -1.287416e-02 6.125880e-03 ... 8.052600e-03 9.611520e-03 -4.168400e-03 1.751170e-03 0.000000e+00 -1.751170e-03 4.168400e-03 -9.611520e-03 -8.052600e-03 ... 2.103714e-02 -1.023569e-02 2.382180e-02 1.836909e-02 0.000000e+00 -1.836909e-02 -2.382180e-02 1.023569e-02 -2.103714e-02 ... 1.536890e-02 -6.009450e-03 5.375324e-02 -1.265655e-01 0.000000e+00 1.265655e-01 -5.375324e-02 6.009450e-03 -1.536890e-02 ... 1.851466e-02 -1.872620e-03 2.076086e-02 -2.996168e-01 0.000000e+00 2.996168e-01 -2.076086e-02 1.872620e-03 -1.851466e-02 ... 1.536890e-02 -6.009450e-03 5.375324e-02 -1.265655e-01 0.000000e+00 1.265655e-01 -5.375324e-02 6.009450e-03 -1.536890e-02 ... 2.103714e-02 -1.023569e-02 2.382180e-02 1.836909e-02 0.000000e+00 -1.836909e-02 -2.382180e-02 1.023569e-02 -2.103714e-02 ... 8.052600e-03 9.611520e-03 -4.168400e-03 1.751170e-03 0.000000e+00 -1.751170e-03 4.168400e-03 -9.611520e-03 -8.052600e-03 ... -6.125880e-03 1.287416e-02 5.641530e-03 8.957260e-03 0.000000e+00 -8.957260e-03 -5.641530e-03 -1.287416e-02 6.125880e-03 ... ]';
github
jbhuang0604/LapSRN-master
spyrHt.m
.m
LapSRN-master/utils/matlabPyrTools/spyrHt.m
305
utf_8
06e83c1f45c1a99e242fa7ea37093a11
% [HEIGHT] = spyrHt(INDICES) % % Compute height of steerable pyramid with given index matrix. % Eero Simoncelli, 6/96. function [ht] = spyrHt(pind) nbands = spyrNumBands(pind); % Don't count lowpass, or highpass residual bands if (size(pind,1) > 2) ht = (size(pind,1)-2)/nbands; else ht = 0; end
github
jbhuang0604/LapSRN-master
spyrBand.m
.m
LapSRN-master/utils/matlabPyrTools/spyrBand.m
819
utf_8
7d15b24244e521c9e85c68b3037f569b
% [LEV,IND] = spyrBand(PYR,INDICES,LEVEL,BAND) % % Access a band from a steerable pyramid. % % LEVEL indicates the scale (finest = 1, coarsest = spyrHt(INDICES)). % % BAND (optional, default=1) indicates which subband % (1 = vertical, rest proceeding anti-clockwise). % Eero Simoncelli, 6/96. function res = spyrBand(pyr,pind,level,band) if (exist('level') ~= 1) level = 1; end if (exist('band') ~= 1) band = 1; end nbands = spyrNumBands(pind); if ((band > nbands) | (band < 1)) error(sprintf('Bad band number (%d) should be in range [1,%d].', band, nbands)); end maxLev = spyrHt(pind); if ((level > maxLev) | (level < 1)) error(sprintf('Bad level number (%d), should be in range [1,%d].', level, maxLev)); end firstband = 1 + band + nbands*(level-1); res = pyrBand(pyr, pind, firstband);
github
jbhuang0604/LapSRN-master
wpyrBand.m
.m
LapSRN-master/utils/matlabPyrTools/wpyrBand.m
873
utf_8
12e08d90ccd6261b737e2d3c5ac5b1e7
% RES = wpyrBand(PYR, INDICES, LEVEL, BAND) % % Access a subband from a separable QMF/wavelet pyramid. % % LEVEL (optional, default=1) indicates the scale (finest = 1, % coarsest = wpyrHt(INDICES)). % % BAND (optional, default=1) indicates which subband (1=horizontal, % 2=vertical, 3=diagonal). % Eero Simoncelli, 6/96. function im = wpyrBand(pyr,pind,level,band) if (exist('level') ~= 1) level = 1; end if (exist('band') ~= 1) band = 1; end if ((pind(1,1) == 1) | (pind(1,2) ==1)) nbands = 1; else nbands = 3; end if ((band > nbands) | (band < 1)) error(sprintf('Bad band number (%d) should be in range [1,%d].', band, nbands)); end maxLev = wpyrHt(pind); if ((level > maxLev) | (level < 1)) error(sprintf('Bad level number (%d), should be in range [1,%d].', level, maxLev)); end band = band + nbands*(level-1); im = pyrBand(pyr,pind,band);
github
jbhuang0604/LapSRN-master
skew2.m
.m
LapSRN-master/utils/matlabPyrTools/skew2.m
478
utf_8
b304767117ab43e408c5757ab9e3402d
% S = SKEW2(MTX,MEAN,VAR) % % Sample skew (third moment divided by variance^3/2) of a matrix. % MEAN (optional) and VAR (optional) make the computation faster. function res = skew2(mtx, mn, v) if (exist('mn') ~= 1) mn = mean2(mtx); end if (exist('v') ~= 1) v = var2(mtx,mn); end if (isreal(mtx)) res = mean(mean((mtx-mn).^3)) / (v^(3/2)); else res = mean(mean(real(mtx-mn).^3)) / (real(v)^(3/2)) + ... i * mean(mean(imag(mtx-mn).^3)) / (imag(v)^(3/2)); end
github
jbhuang0604/LapSRN-master
imStats.m
.m
LapSRN-master/utils/matlabPyrTools/imStats.m
1,217
utf_8
aab8c3264c5939806bbca5657c925734
% imStats(IM1,IM2) % % Report image (matrix) statistics. % When called on a single image IM1, report min, max, mean, stdev, skew, % and kurtosis (4th moment about the mean, divided by squared variance) % % When called on two images (IM1 and IM2), report min, max, mean, % stdev of the difference, and also SNR (relative to IM1). % Eero Simoncelli, 6/96. function [] = imStats(im1,im2) if (~isreal(im1)) error('Args must be real-valued matrices'); end if (exist('im2') == 1) difference = im1 - im2; [mn,mx] = range2(difference); mean = mean2(difference); v = var2(difference,mean); if (v < realmin) snr = Inf; else snr = 10 * log10(var2(im1)/v); end fprintf(1, 'Difference statistics:\n'); fprintf(1, ' Range: [%c, %c]\n',mn,mx); fprintf(1, ' Mean: %f, Stdev (rmse): %f, SNR (dB): %f\n',... mean,sqrt(v),snr); else [mn,mx] = range2(im1); mean = mean2(im1); var = var2(im1,mean); stdev = sqrt(real(var))+sqrt(imag(var)); sk = skew2(im1, mean, stdev^2); kurt = kurt2(im1, mean, stdev^2); fprintf(1, 'Image statistics:\n'); fprintf(1, ' Range: [%f, %f]\n',mn,mx); fprintf(1, ' Mean: %f, Stdev: %f, Skew: %f, Kurt: %f\n',mean,stdev,sk,kurt); end
github
jbhuang0604/LapSRN-master
innerProd.m
.m
LapSRN-master/utils/matlabPyrTools/innerProd.m
314
utf_8
e2ea166f9b3ddbc08cb54ef697343d06
% RES = innerProd(MTX) % % Compute (MTX' * MTX) efficiently (i.e., without copying the matrix) % % NOTE: This function used to call a MEX function (C code) to avoid copying, but % newer versions of matlab have eliminated the overhead of the % simpler form below. function res = innerProd(mtx) res = mtx' * mtx;
github
jbhuang0604/LapSRN-master
reconSFpyr.m
.m
LapSRN-master/utils/matlabPyrTools/reconSFpyr.m
3,114
utf_8
ebb08817efc597692b9026a84e2a6906
% RES = reconSFpyr(PYR, INDICES, LEVS, BANDS, TWIDTH) % % Reconstruct image from its steerable pyramid representation, in the Fourier % domain, as created by buildSFpyr. % % PYR is a vector containing the N pyramid subbands, ordered from fine % to coarse. INDICES is an Nx2 matrix containing the sizes of % each subband. This is compatible with the MatLab Wavelet toolbox. % % LEVS (optional) should be a list of levels to include, or the string % 'all' (default). 0 corresonds to the residual highpass subband. % 1 corresponds to the finest oriented scale. The lowpass band % corresponds to number spyrHt(INDICES)+1. % % BANDS (optional) should be a list of bands to include, or the string % 'all' (default). 1 = vertical, rest proceeding anti-clockwise. % % TWIDTH is the width of the transition region of the radial lowpass % function, in octaves (default = 1, which gives a raised cosine for % the bandpass filters). %%% MODIFIED VERSION, 7/04, uses different lookup table for radial frequency! % Eero Simoncelli, 5/97. function res = reconSFpyr(pyr, pind, levs, bands, twidth) %%------------------------------------------------------------ %% DEFAULTS: if (exist('levs') ~= 1) levs = 'all'; end if (exist('bands') ~= 1) bands = 'all'; end if (exist('twidth') ~= 1) twidth = 1; elseif (twidth <= 0) fprintf(1,'Warning: TWIDTH must be positive. Setting to 1.\n'); twidth = 1; end %%------------------------------------------------------------ nbands = spyrNumBands(pind); maxLev = 1+spyrHt(pind); if strcmp(levs,'all') levs = [0:maxLev]'; else if (any(levs > maxLev) | any(levs < 0)) error(sprintf('Level numbers must be in the range [0, %d].', maxLev)); end levs = levs(:); end if strcmp(bands,'all') bands = [1:nbands]'; else if (any(bands < 1) | any(bands > nbands)) error(sprintf('Band numbers must be in the range [1,3].', nbands)); end bands = bands(:); end %---------------------------------------------------------------------- dims = pind(1,:); ctr = ceil((dims+0.5)/2); [xramp,yramp] = meshgrid( ([1:dims(2)]-ctr(2))./(dims(2)/2), ... ([1:dims(1)]-ctr(1))./(dims(1)/2) ); angle = atan2(yramp,xramp); log_rad = sqrt(xramp.^2 + yramp.^2); log_rad(ctr(1),ctr(2)) = log_rad(ctr(1),ctr(2)-1); log_rad = log2(log_rad); %% Radial transition function (a raised cosine in log-frequency): [Xrcos,Yrcos] = rcosFn(twidth,(-twidth/2),[0 1]); Yrcos = sqrt(Yrcos); YIrcos = sqrt(abs(1.0 - Yrcos.^2)); if (size(pind,1) == 2) if (any(levs==1)) resdft = fftshift(fft2(pyrBand(pyr,pind,2))); else resdft = zeros(pind(2,:)); end else resdft = reconSFpyrLevs(pyr(1+prod(pind(1,:)):size(pyr,1)), ... pind(2:size(pind,1),:), ... log_rad, Xrcos, Yrcos, angle, nbands, levs, bands); end lo0mask = pointOp(log_rad, YIrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0); resdft = resdft .* lo0mask; %% residual highpass subband if any(levs == 0) hi0mask = pointOp(log_rad, Yrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0); hidft = fftshift(fft2(subMtx(pyr, pind(1,:)))); resdft = resdft + hidft .* hi0mask; end res = real(ifft2(ifftshift(resdft)));
github
jbhuang0604/LapSRN-master
corrDn.m
.m
LapSRN-master/utils/matlabPyrTools/corrDn.m
2,273
utf_8
22bd1475092a492cb03a6e4134332d24
% RES = corrDn(IM, FILT, EDGES, STEP, START, STOP) % % Compute correlation of matrices IM with FILT, followed by % downsampling. These arguments should be 1D or 2D matrices, and IM % must be larger (in both dimensions) than FILT. The origin of filt % is assumed to be floor(size(filt)/2)+1. % % EDGES is a string determining boundary handling: % 'circular' - Circular convolution % 'reflect1' - Reflect about the edge pixels % 'reflect2' - Reflect, doubling the edge pixels % 'repeat' - Repeat the edge pixels % 'zero' - Assume values of zero outside image boundary % 'extend' - Reflect and invert (continuous values and derivs) % 'dont-compute' - Zero output when filter overhangs input boundaries % % Downsampling factors are determined by STEP (optional, default=[1 1]), % which should be a 2-vector [y,x]. % % The window over which the convolution occurs is specfied by START % (optional, default=[1,1], and STOP (optional, default=size(IM)). % % NOTE: this operation corresponds to multiplication of a signal % vector by a matrix whose rows contain copies of the FILT shifted by % multiples of STEP. See upConv.m for the operation corresponding to % the transpose of this matrix. % Eero Simoncelli, 6/96, revised 2/97. function res = corrDn(im, filt, edges, step, start, stop) %% NOTE: THIS CODE IS NOT ACTUALLY USED! (MEX FILE IS CALLED INSTEAD) %fprintf(1,'WARNING: You should compile the MEX version of "corrDn.c",\n found in the MEX subdirectory of matlabPyrTools, and put it in your matlab path. It is MUCH faster, and provides more boundary-handling options.\n'); %------------------------------------------------------------ %% OPTIONAL ARGS: if (exist('edges') == 1) if (strcmp(edges,'reflect1') ~= 1) warning('Using REFLECT1 edge-handling (use MEX code for other options).'); end end if (exist('step') ~= 1) step = [1,1]; end if (exist('start') ~= 1) start = [1,1]; end if (exist('stop') ~= 1) stop = size(im); end %------------------------------------------------------------ % Reverse order of taps in filt, to do correlation instead of convolution filt = filt(size(filt,1):-1:1,size(filt,2):-1:1); tmp = rconv2(im,filt); res = tmp(start(1):step(1):stop(1),start(2):step(2):stop(2));
github
jbhuang0604/LapSRN-master
vectify.m
.m
LapSRN-master/utils/matlabPyrTools/vectify.m
186
utf_8
1da0e519af06d6baaff1decc40dc3702
% [VEC] = columnize(MTX) % % Pack elements of MTX into a column vector. Just provides a % function-call notatoin for the operation MTX(:) function vec = columnize(mtx) vec = mtx(:);
github
jbhuang0604/LapSRN-master
maxPyrHt.m
.m
LapSRN-master/utils/matlabPyrTools/maxPyrHt.m
603
utf_8
019e5ce9d036a893ec979c63f51ff54a
% HEIGHT = maxPyrHt(IMSIZE, FILTSIZE) % % Compute maximum pyramid height for given image and filter sizes. % Specifically: the number of corrDn operations that can be sequentially % performed when subsampling by a factor of 2. % Eero Simoncelli, 6/96. function height = maxPyrHt(imsz, filtsz) imsz = imsz(:); filtsz = filtsz(:); if any(imsz == 1) % 1D image imsz = prod(imsz); filtsz = prod(filtsz); elseif any(filtsz == 1) % 2D image, 1D filter filtsz = [filtsz(1); filtsz(1)]; end if any(imsz < filtsz) height = 0; else height = 1 + maxPyrHt( floor(imsz/2), filtsz ); end
github
jbhuang0604/LapSRN-master
buildSpyrLevs.m
.m
LapSRN-master/utils/matlabPyrTools/buildSpyrLevs.m
861
utf_8
a5fa1e98161a8137e666c1406c28a748
% [PYR, INDICES] = buildSpyrLevs(LOIM, HEIGHT, LOFILT, BFILTS, EDGES) % % Recursive function for constructing levels of a steerable pyramid. This % is called by buildSpyr, and is not usually called directly. % Eero Simoncelli, 6/96. function [pyr,pind] = buildSpyrLevs(lo0,ht,lofilt,bfilts,edges); if (ht <= 0) pyr = lo0(:); pind = size(lo0); else % Assume square filters: bfiltsz = round(sqrt(size(bfilts,1))); bands = zeros(prod(size(lo0)),size(bfilts,2)); bind = zeros(size(bfilts,2),2); for b = 1:size(bfilts,2) filt = reshape(bfilts(:,b),bfiltsz,bfiltsz); band = corrDn(lo0, filt, edges); bands(:,b) = band(:); bind(b,:) = size(band); end lo = corrDn(lo0, lofilt, edges, [2 2], [1 1]); [npyr,nind] = buildSpyrLevs(lo, ht-1, lofilt, bfilts, edges); pyr = [bands(:); npyr]; pind = [bind; nind]; end
github
jbhuang0604/LapSRN-master
showSpyr.m
.m
LapSRN-master/utils/matlabPyrTools/showSpyr.m
5,213
utf_8
bc643d88c491a55c0a0abb5e86c91757
% RANGE = showSpyr (PYR, INDICES, RANGE, GAP, LEVEL_SCALE_FACTOR) % % Display a steerable pyramid, specified by PYR and INDICES % (see buildSpyr), in the current figure. The highpass band is not shown. % % RANGE is a 2-vector specifying the values that map to black and % white, respectively. These values are scaled by % LEVEL_SCALE_FACTOR^(lev-1) for bands at each level. Passing a value % of 'auto1' sets RANGE to the min and max values of MATRIX. 'auto2' % sets RANGE to 3 standard deviations below and above 0.0. In both of % these cases, the lowpass band is independently scaled. A value of % 'indep1' sets the range of each subband independently, as in a call % to showIm(subband,'auto1'). Similarly, 'indep2' causes each subband % to be scaled independently as if by showIm(subband,'indep2'). % The default value for RANGE is 'auto2'. % % GAP (optional, default=1) specifies the gap in pixels to leave % between subbands. % % LEVEL_SCALE_FACTOR indicates the relative scaling between pyramid % levels. This should be set to the sum of the kernel taps of the % lowpass filter used to construct the pyramid (default is 2, which is % correct for L2-normalized filters. % Eero Simoncelli, 2/97. function [range] = showSpyr(pyr, pind, range, gap, scale); nbands = spyrNumBands(pind); %------------------------------------------------------------ %% OPTIONAL ARGS: if (exist('range') ~= 1) range = 'auto2'; end if (exist('gap') ~= 1) gap = 1; end if (exist('scale') ~= 1) scale = 2; end %------------------------------------------------------------ ht = spyrHt(pind); nind = size(pind,1); %% Auto range calculations: if strcmp(range,'auto1') range = ones(nind,1); band = spyrHigh(pyr,pind); [mn,mx] = range2(band); for lnum = 1:ht for bnum = 1:nbands band = spyrBand(pyr,pind,lnum,bnum)/(scale^(lnum-1)); range((lnum-1)*nbands+bnum+1) = scale^(lnum-1); [bmn,bmx] = range2(band); mn = min(mn, bmn); mx = max(mx, bmx); end end range = range * [mn mx]; % outer product band = pyrLow(pyr,pind); [mn,mx] = range2(band); range(nind,:) = [mn, mx]; elseif strcmp(range,'indep1') range = zeros(nind,2); for bnum = 1:nind band = pyrBand(pyr,pind,bnum); [mn,mx] = range2(band); range(bnum,:) = [mn mx]; end elseif strcmp(range,'auto2') range = ones(nind,1); band = spyrHigh(pyr,pind); sqsum = sum(sum(band.^2)); numpixels = prod(size(band)); for lnum = 1:ht for bnum = 1:nbands band = spyrBand(pyr,pind,lnum,bnum)/(scale^(lnum-1)); sqsum = sqsum + sum(sum(band.^2)); numpixels = numpixels + prod(size(band)); range((lnum-1)*nbands+bnum+1) = scale^(lnum-1); end end stdev = sqrt(sqsum/(numpixels-1)); range = range * [ -3*stdev 3*stdev ]; % outer product band = pyrLow(pyr,pind); av = mean2(band); stdev = sqrt(var2(band)); range(nind,:) = [av-2*stdev,av+2*stdev]; elseif strcmp(range,'indep2') range = zeros(nind,2); for bnum = 1:(nind-1) band = pyrBand(pyr,pind,bnum); stdev = sqrt(var2(band)); range(bnum,:) = [ -3*stdev 3*stdev ]; end band = pyrLow(pyr,pind); av = mean2(band); stdev = sqrt(var2(band)); range(nind,:) = [av-2*stdev,av+2*stdev]; elseif isstr(range) error(sprintf('Bad RANGE argument: %s',range)) elseif ((size(range,1) == 1) & (size(range,2) == 2)) scales = scale.^[0:(ht-1)]; scales = ones(nbands,1) * scales; %outer product scales = [1; scales(:); scale^ht]; %tack on highpass and lowpass range = scales * range; % outer product band = pyrLow(pyr,pind); range(nind,:) = range(nind,:) + mean2(band) - mean(range(nind,:)); end % CLEAR FIGURE: clf; colormap(gray); cmap = get(gcf,'Colormap'); nshades = size(cmap,1); % Find background color index: clr = get(gcf,'Color'); bg = 1; dist = norm(cmap(bg,:)-clr); for n = 1:nshades ndist = norm(cmap(n,:)-clr); if (ndist < dist) dist = ndist; bg = n; end end %% Compute positions of subbands: llpos = ones(nind,2); if (nbands == 2) ncols = 1; nrows = 2; else ncols = ceil((nbands+1)/2); nrows = ceil(nbands/2); end relpos = [ (1-nrows):0, zeros(1,(ncols-1)); ... zeros(1,nrows), -1:-1:(1-ncols) ]'; if (nbands > 1) mvpos = [-1 -1]; else mvpos = [0 -1]; end basepos = [0 0]; for lnum = 1:ht ind1 = (lnum-1)*nbands + 2; sz = pind(ind1,:)+gap; basepos = basepos + mvpos .* sz; if (nbands < 5) % to align edges... sz = sz + gap*(ht-lnum+1); end llpos(ind1:ind1+nbands-1,:) = relpos * diag(sz) + ones(nbands,1)*basepos; end % lowpass band sz = pind(nind-1,:)+gap; basepos = basepos + mvpos .* sz; llpos(nind,:) = basepos; %% Make position list positive, and allocate appropriate image: llpos = llpos - ones(nind,1)*min(llpos) + 1; llpos(1,:) = [1 1]; urpos = llpos + pind - 1; d_im = bg + zeros(max(urpos)); %% Paste bands into image, (im-r1)*(nshades-1)/(r2-r1) + 1.5 for bnum=2:nind mult = (nshades-1) / (range(bnum,2)-range(bnum,1)); d_im(llpos(bnum,1):urpos(bnum,1), llpos(bnum,2):urpos(bnum,2)) = ... mult*pyrBand(pyr,pind,bnum) + (1.5-mult*range(bnum,1)); end hh = image(d_im); axis('off'); pixelAxes(size(d_im),'full'); set(hh,'UserData',range);
github
jbhuang0604/LapSRN-master
histo.m
.m
LapSRN-master/utils/matlabPyrTools/histo.m
1,835
utf_8
e76d8956cd1d59f518a8146dc5145f9b
% [N,X] = histo(MTX, nbinsOrBinsize, binCenter); % % Compute a histogram of (all) elements of MTX. N contains the histogram % counts, X is a vector containg the centers of the histogram bins. % % nbinsOrBinsize (optional, default = 101) specifies either % the number of histogram bins, or the negative of the binsize. % % binCenter (optional, default = mean2(MTX)) specifies a center position % for (any one of) the histogram bins. % % How does this differ from MatLab's HIST function? This function: % - allows uniformly spaced bins only. % +/- operates on all elements of MTX, instead of columnwise. % + is much faster (approximately a factor of 80 on my machine). % + allows specification of number of bins OR binsize. Default=101 bins. % + allows (optional) specification of binCenter. % Eero Simoncelli, 3/97. function [N, X] = histo(mtx, nbins, binCtr) %% NOTE: THIS CODE IS NOT ACTUALLY USED! (MEX FILE IS CALLED INSTEAD) fprintf(1,'WARNING: You should compile the MEX version of "histo.c",\n found in the MEX subdirectory of matlabPyrTools, and put it in your matlab path. It is MUCH faster.\n'); mtx = mtx(:); %------------------------------------------------------------ %% OPTIONAL ARGS: [mn,mx] = range2(mtx); if (exist('binCtr') ~= 1) binCtr = mean(mtx); end if (exist('nbins') == 1) if (nbins < 0) binSize = -nbins; else binSize = ((mx-mn)/nbins); tmpNbins = round((mx-binCtr)/binSize) - round((mn-binCtr)/binSize); if (tmpNbins ~= nbins) warning('Using %d bins instead of requested number (%d)',tmpNbins,nbins); end end else binSize = ((mx-mn)/101); end firstBin = binCtr + binSize*round( (mn-binCtr)/binSize ); tmpNbins = round((mx-binCtr)/binSize) - round((mn-binCtr)/binSize); bins = firstBin + binSize*[0:tmpNbins]; [N, X] = hist(mtx, bins);
github
jbhuang0604/LapSRN-master
lplot.m
.m
LapSRN-master/utils/matlabPyrTools/lplot.m
1,009
utf_8
87c83936af0b318d55077862065b56df
% lplot(VEC, XRANGE) % % Plot VEC, a vector, in "lollipop" format. % XRANGE (optional, default = [1,length(VEC)]), should be a 2-vector % specifying the X positions (for labeling purposes) of the first and % last sample of VEC. % Mark Liberman, Linguistics Dept, UPenn, 1994. function lplot(x,xrange) if (exist('xrange') ~= 1) xrange = [1,length(x)]; end msize = size(x); if ( msize(2) == 1) x = x'; elseif (msize(1) ~= 1) error('First arg must be a vector'); end if (~isreal(x)) fprintf(1,'Warning: Imaginary part of signal ignored\n'); x = abs(x); end N = length(x); index = xrange(1) + (xrange(2)-xrange(1))*[0:(N-1)]/(N-1); xinc = index(2)-index(1); xx = [zeros(1,N);x;zeros(1,N)]; indexis = [index;index;index]; xdiscrete = [0 xx(:)' 0]; idiscrete = [index(1)-xinc indexis(:)' index(N)+xinc]; [mn,mx] = range2(xdiscrete); ypad = (mx-mn)/12; % MAGIC NUMBER: graph padding plot(idiscrete, xdiscrete, index, x, 'o'); axis([index(1)-xinc, index(N)+xinc, mn-ypad, mx+ypad]); return
github
jbhuang0604/LapSRN-master
blurDn.m
.m
LapSRN-master/utils/matlabPyrTools/blurDn.m
1,364
utf_8
d528010bfd2b4c50e7dbb2aede757214
% RES = blurDn(IM, LEVELS, FILT) % % Blur and downsample an image. The blurring is done with filter % kernel specified by FILT (default = 'binom5'), which can be a string % (to be passed to namedFilter), a vector (applied separably as a 1D % convolution kernel in X and Y), or a matrix (applied as a 2D % convolution kernel). The downsampling is always by 2 in each % direction. % % The procedure is applied recursively LEVELS times (default=1). % Eero Simoncelli, 3/97. function res = blurDn(im, nlevs, filt) %------------------------------------------------------------ %% OPTIONAL ARGS: if (exist('nlevs') ~= 1) nlevs = 1; end if (exist('filt') ~= 1) filt = 'binom5'; end %------------------------------------------------------------ if isstr(filt) filt = namedFilter(filt); end filt = filt/sum(filt(:)); if nlevs > 1 im = blurDn(im,nlevs-1,filt); end if (nlevs >= 1) if (any(size(im)==1)) if (~any(size(filt)==1)) error('Cant apply 2D filter to 1D signal'); end if (size(im,2)==1) filt = filt(:); else filt = filt(:)'; end res = corrDn(im,filt,'reflect1',(size(im)~=1)+1); elseif (any(size(filt)==1)) filt = filt(:); res = corrDn(im,filt,'reflect1',[2 1]); res = corrDn(res,filt','reflect1',[1 2]); else res = corrDn(im,filt,'reflect1',[2 2]); end else res = im; end
github
jbhuang0604/LapSRN-master
reconSpyrLevs.m
.m
LapSRN-master/utils/matlabPyrTools/reconSpyrLevs.m
1,126
utf_8
1f10e3cea5d79a4f4a30d979f3bb1298
% RES = reconSpyrLevs(PYR,INDICES,LOFILT,BFILTS,EDGES,LEVS,BANDS) % % Recursive function for reconstructing levels of a steerable pyramid % representation. This is called by reconSpyr, and is not usually % called directly. % Eero Simoncelli, 6/96. function res = reconSpyrLevs(pyr,pind,lofilt,bfilts,edges,levs,bands); nbands = size(bfilts,2); lo_ind = nbands+1; res_sz = pind(1,:); % Assume square filters: bfiltsz = round(sqrt(size(bfilts,1))); if any(levs > 1) if (size(pind,1) > lo_ind) nres = reconSpyrLevs( pyr(1+sum(prod(pind(1:lo_ind-1,:)')):size(pyr,1)), ... pind(lo_ind:size(pind,1),:), ... lofilt, bfilts, edges, levs-1, bands); else nres = pyrBand(pyr,pind,lo_ind); % lowpass subband end res = upConv(nres, lofilt, edges, [2 2], [1 1], res_sz); else res = zeros(res_sz); end if any(levs == 1) ind = 1; for b = 1:nbands if any(bands == b) bfilt = reshape(bfilts(:,b), bfiltsz, bfiltsz); res = upConv(reshape(pyr(ind:ind+prod(res_sz)-1), res_sz(1), res_sz(2)), ... bfilt, edges, [1 1], [1 1], res_sz, res); end ind = ind + prod(res_sz); end end
github
jbhuang0604/LapSRN-master
mkSine.m
.m
LapSRN-master/utils/matlabPyrTools/mkSine.m
1,725
utf_8
35c6d83f70860ab6defcbdcf7366d89e
% IM = mkSine(SIZE, PERIOD, DIRECTION, AMPLITUDE, PHASE, ORIGIN) % or % IM = mkSine(SIZE, FREQ, AMPLITUDE, PHASE, ORIGIN) % % Compute a matrix of dimension SIZE (a [Y X] 2-vector, or a scalar) % containing samples of a 2D sinusoid, with given PERIOD (in pixels), % DIRECTION (radians, CW from X-axis, default = 0), AMPLITUDE (default % = 1), and PHASE (radians, relative to ORIGIN, default = 0). ORIGIN % defaults to the center of the image. % % In the second form, FREQ is a 2-vector of frequencies (radians/pixel). % Eero Simoncelli, 6/96. function [res] = mkSine(sz, per_freq, dir_amp, amp_phase, phase_orig, orig) %------------------------------------------------------------ %% OPTIONAL ARGS: if (prod(size(per_freq)) == 2) frequency = norm(per_freq); direction = atan2(per_freq(1),per_freq(2)); if (exist('dir_amp') == 1) amplitude = dir_amp; else amplitude = 1; end if (exist('amp_phase') == 1) phase = amp_phase; else phase = 0; end if (exist('phase_orig') == 1) origin = phase_orig; end if (exist('orig') == 1) error('Too many arguments for (second form) of mkSine'); end else frequency = 2*pi/per_freq; if (exist('dir_amp') == 1) direction = dir_amp; else direction = 0; end if (exist('amp_phase') == 1) amplitude = amp_phase; else amplitude = 1; end if (exist('phase_orig') == 1) phase = phase_orig; else phase = 0; end if (exist('orig') == 1) origin = orig; end end %------------------------------------------------------------ if (exist('origin') == 1) res = amplitude*sin(mkRamp(sz, direction, frequency, phase, origin)); else res = amplitude*sin(mkRamp(sz, direction, frequency, phase)); end
github
jbhuang0604/LapSRN-master
buildSFpyrLevs.m
.m
LapSRN-master/utils/matlabPyrTools/buildSFpyrLevs.m
1,891
utf_8
52ab858761411b2a5a75e7de641259cf
% [PYR, INDICES] = buildSFpyrLevs(LODFT, LOGRAD, XRCOS, YRCOS, ANGLE, HEIGHT, NBANDS) % % Recursive function for constructing levels of a steerable pyramid. This % is called by buildSFpyr, and is not usually called directly. % Eero Simoncelli, 5/97. function [pyr,pind] = buildSFpyrLevs(lodft,log_rad,Xrcos,Yrcos,angle,ht,nbands); if (ht <= 0) lo0 = ifft2(ifftshift(lodft)); pyr = real(lo0(:)); pind = size(lo0); else bands = zeros(prod(size(lodft)), nbands); bind = zeros(nbands,2); % log_rad = log_rad + 1; Xrcos = Xrcos - log2(2); % shift origin of lut by 1 octave. lutsize = 1024; Xcosn = pi*[-(2*lutsize+1):(lutsize+1)]/lutsize; % [-2*pi:pi] order = nbands-1; %% divide by sqrt(sum_(n=0)^(N-1) cos(pi*n/N)^(2(N-1)) ) %% Thanks to Patrick Teo for writing this out :) const = (2^(2*order))*(factorial(order)^2)/(nbands*factorial(2*order)); Ycosn = sqrt(const) * (cos(Xcosn)).^order; himask = pointOp(log_rad, Yrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0); for b = 1:nbands anglemask = pointOp(angle, Ycosn, Xcosn(1)+pi*(b-1)/nbands, Xcosn(2)-Xcosn(1)); banddft = ((-sqrt(-1))^order) .* lodft .* anglemask .* himask; band = ifft2(ifftshift(banddft)); bands(:,b) = real(band(:)); bind(b,:) = size(band); end dims = size(lodft); ctr = ceil((dims+0.5)/2); lodims = ceil((dims-0.5)/2); loctr = ceil((lodims+0.5)/2); lostart = ctr-loctr+1; loend = lostart+lodims-1; log_rad = log_rad(lostart(1):loend(1),lostart(2):loend(2)); angle = angle(lostart(1):loend(1),lostart(2):loend(2)); lodft = lodft(lostart(1):loend(1),lostart(2):loend(2)); YIrcos = abs(sqrt(1.0 - Yrcos.^2)); lomask = pointOp(log_rad, YIrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0); lodft = lomask .* lodft; [npyr,nind] = buildSFpyrLevs(lodft, log_rad, Xrcos, Yrcos, angle, ht-1, nbands); pyr = [bands(:); npyr]; pind = [bind; nind]; end
github
jbhuang0604/LapSRN-master
pixelAxes.m
.m
LapSRN-master/utils/matlabPyrTools/pixelAxes.m
1,983
utf_8
1b2a2bfddd425fee2ccd276f3948cec7
% [ZOOM] = pixelAxes(DIMS, ZOOM) % % Set the axes of the current plot to cover a multiple of DIMS pixels, % thereby eliminating screen aliasing artifacts when displaying an % image of size DIMS. % % ZOOM (optional, default='same') expresses the desired number of % samples displayed per screen pixel. It should be a scalar, which % will be rounded to the nearest integer, or 1 over an integer. It % may also be the string 'same' or 'auto', in which case the value is chosen so % as to produce an image closest in size to the currently displayed % image. It may also be the string 'full', in which case the image is % made as large as possible while still fitting in the window. % Eero Simoncelli, 2/97. function [zoom] = pixelAxes(dims, zoom) %------------------------------------------------------------ %% OPTIONAL ARGS: if (exist('zoom') ~= 1) zoom = 'same'; end %% Reverse dimension order, since Figure Positions reported as (x,y). dims = dims(2:-1:1); %% Use MatLab's axis function to force square pixels, etc: axis('image'); ax = gca; oldunits = get(ax,'Units'); if strcmp(zoom,'full'); set(ax,'Units','normalized'); set(ax,'Position',[0 0 1 1]); zoom = 'same'; end set(ax,'Units','pixels'); pos = get(ax,'Position'); ctr = pos(1:2)+pos(3:4)/2; if (strcmp(zoom,'same') | strcmp(zoom,'auto')) %% HACK: enlarge slightly so that floor doesn't round down zoom = min( pos(3:4) ./ (dims - 1) ); elseif isstr(zoom) error(sprintf('Bad ZOOM argument: %s',zoom)); end %% Force zoom value to be an integer, or inverse integer. if (zoom < 0.75) zoom = 1/ceil(1/zoom); %% Round upward, subtracting 0.5 to avoid floating point errors. newsz = ceil(zoom*(dims-0.5)); else zoom = floor(zoom + 0.001); % Avoid floating pt errors if (zoom < 1.5) % zoom=1 zoom = 1; newsz = dims + 0.5; else newsz = zoom*(dims-1) + mod(zoom,2); end end set(ax,'Position', [floor(ctr-newsz/2)+0.5, newsz] ) % Restore units set(ax,'Units',oldunits);
github
jbhuang0604/LapSRN-master
pyrBandIndices.m
.m
LapSRN-master/utils/matlabPyrTools/pyrBandIndices.m
589
utf_8
28f90484526c294bdb24bdbf8014012d
% RES = pyrBandIndices(INDICES, BAND_NUM) % % Return indices for accessing a subband from a pyramid % (gaussian, laplacian, QMF/wavelet, steerable). % Eero Simoncelli, 6/96. function indices = pyrBandIndices(pind,band) if ((band > size(pind,1)) | (band < 1)) error(sprintf('BAND_NUM must be between 1 and number of pyramid bands (%d).', ... size(pind,1))); end if (size(pind,2) ~= 2) error('INDICES must be an Nx2 matrix indicating the size of the pyramid subbands'); end ind = 1; for l=1:band-1 ind = ind + prod(pind(l,:)); end indices = ind:ind+prod(pind(band,:))-1;
github
jbhuang0604/LapSRN-master
pointOp.m
.m
LapSRN-master/utils/matlabPyrTools/pointOp.m
1,209
utf_8
537b70083d9e7d7ffe4810e966c047f9
% RES = pointOp(IM, LUT, ORIGIN, INCREMENT, WARNINGS) % % Apply a point operation, specified by lookup table LUT, to image IM. % LUT must be a row or column vector, and is assumed to contain % (equi-spaced) samples of the function. ORIGIN specifies the % abscissa associated with the first sample, and INCREMENT specifies the % spacing between samples. Between-sample values are estimated via % linear interpolation. If WARNINGS is non-zero, the function prints % a warning whenever the lookup table is extrapolated. % % This function is much faster than MatLab's interp1, and allows % extrapolation beyond the lookup table domain. The drawbacks are % that the lookup table must be equi-spaced, and the interpolation is % linear. % Eero Simoncelli, 8/96. function res = pointOp(im, lut, origin, increment, warnings) %% NOTE: THIS CODE IS NOT ACTUALLY USED! (MEX FILE IS CALLED INSTEAD) % fprintf(1,'WARNING: You should compile the MEX version of "pointOp.c",\n found in the MEX subdirectory of matlabPyrTools, and put it in your matlab path. It is MUCH faster.\n'); X = origin + increment*[0:size(lut(:),1)-1]; Y = lut(:); res = reshape(interp1(X, Y, im(:), 'linear', 'extrap'),size(im));
github
jbhuang0604/LapSRN-master
reconWpyr.m
.m
LapSRN-master/utils/matlabPyrTools/reconWpyr.m
3,992
utf_8
859a606f214bce204ce3c9ea18c0fc87
% RES = reconWpyr(PYR, INDICES, FILT, EDGES, LEVS, BANDS) % % Reconstruct image from its separable orthonormal QMF/wavelet pyramid % representation, as created by buildWpyr. % % PYR is a vector containing the N pyramid subbands, ordered from fine % to coarse. INDICES is an Nx2 matrix containing the sizes of % each subband. This is compatible with the MatLab Wavelet toolbox. % % FILT (optional) can be a string naming a standard filter (see % namedFilter), or a vector which will be used for (separable) % convolution. Default = 'qmf9'. EDGES specifies edge-handling, % and defaults to 'reflect1' (see corrDn). % % LEVS (optional) should be a vector of levels to include, or the string % 'all' (default). 1 corresponds to the finest scale. The lowpass band % corresponds to wpyrHt(INDICES)+1. % % BANDS (optional) should be a vector of bands to include, or the string % 'all' (default). 1=horizontal, 2=vertical, 3=diagonal. This is only used % for pyramids of 2D images. % Eero Simoncelli, 6/96. function res = reconWpyr(pyr, ind, filt, edges, levs, bands) if (nargin < 2) error('First two arguments (PYR INDICES) are required'); end %%------------------------------------------------------------ %% OPTIONAL ARGS: if (exist('filt') ~= 1) filt = 'qmf9'; end if (exist('edges') ~= 1) edges= 'reflect1'; end if (exist('levs') ~= 1) levs = 'all'; end if (exist('bands') ~= 1) bands = 'all'; end %%------------------------------------------------------------ maxLev = 1+wpyrHt(ind); if strcmp(levs,'all') levs = [1:maxLev]'; else if (any(levs > maxLev)) error(sprintf('Level numbers must be in the range [1, %d].', maxLev)); end levs = levs(:); end if strcmp(bands,'all') bands = [1:3]'; else if (any(bands < 1) | any(bands > 3)) error('Band numbers must be in the range [1,3].'); end bands = bands(:); end if isstr(filt) filt = namedFilter(filt); end filt = filt(:); hfilt = modulateFlip(filt); %% For odd-length filters, stagger the sampling lattices: if (mod(size(filt,1),2) == 0) stag = 2; else stag = 1; end %% Compute size of result image: assumes critical sampling (boundaries correct) res_sz = ind(1,:); if (res_sz(1) == 1) loind = 2; res_sz(2) = sum(ind(:,2)); elseif (res_sz(2) == 1) loind = 2; res_sz(1) = sum(ind(:,1)); else loind = 4; res_sz = ind(1,:) + ind(2,:); %%horizontal + vertical bands. hres_sz = [ind(1,1), res_sz(2)]; lres_sz = [ind(2,1), res_sz(2)]; end %% First, recursively collapse coarser scales: if any(levs > 1) if (size(ind,1) > loind) nres = reconWpyr( pyr(1+sum(prod(ind(1:loind-1,:)')):size(pyr,1)), ... ind(loind:size(ind,1),:), filt, edges, levs-1, bands); else nres = pyrBand(pyr, ind, loind); % lowpass subband end if (res_sz(1) == 1) res = upConv(nres, filt', edges, [1 2], [1 stag], res_sz); elseif (res_sz(2) == 1) res = upConv(nres, filt, edges, [2 1], [stag 1], res_sz); else ires = upConv(nres, filt', edges, [1 2], [1 stag], lres_sz); res = upConv(ires, filt, edges, [2 1], [stag 1], res_sz); end else res = zeros(res_sz); end %% Add in reconstructed bands from this level: if any(levs == 1) if (res_sz(1) == 1) upConv(pyrBand(pyr,ind,1), hfilt', edges, [1 2], [1 2], res_sz, res); elseif (res_sz(2) == 1) upConv(pyrBand(pyr,ind,1), hfilt, edges, [2 1], [2 1], res_sz, res); else if any(bands == 1) % horizontal ires = upConv(pyrBand(pyr,ind,1),filt',edges,[1 2],[1 stag],hres_sz); upConv(ires,hfilt,edges,[2 1],[2 1],res_sz,res); %destructively modify res end if any(bands == 2) % vertical ires = upConv(pyrBand(pyr,ind,2),hfilt',edges,[1 2],[1 2],lres_sz); upConv(ires,filt,edges,[2 1],[stag 1],res_sz,res); %destructively modify res end if any(bands == 3) % diagonal ires = upConv(pyrBand(pyr,ind,3),hfilt',edges,[1 2],[1 2],hres_sz); upConv(ires,hfilt,edges,[2 1],[2 1],res_sz,res); %destructively modify res end end end
github
jbhuang0604/LapSRN-master
showWpyr.m
.m
LapSRN-master/utils/matlabPyrTools/showWpyr.m
5,491
utf_8
4bc0b260425f553810ae04afced17fda
% RANGE = showWpyr (PYR, INDICES, RANGE, GAP, LEVEL_SCALE_FACTOR) % % Display a separable QMF/wavelet pyramid, specified by PYR and INDICES % (see buildWpyr), in the current figure. % % RANGE is a 2-vector specifying the values that map to black and % white, respectively. These values are scaled by % LEVEL_SCALE_FACTOR^(lev-1) for bands at each level. Passing a value % of 'auto1' sets RANGE to the min and max values of MATRIX. 'auto2' % sets RANGE to 3 standard deviations below and above 0.0. In both of % these cases, the lowpass band is independently scaled. A value of % 'indep1' sets the range of each subband independently, as in a call % to showIm(subband,'auto1'). Similarly, 'indep2' causes each subband % to be scaled independently as if by showIm(subband,'indep2'). % The default value for RANGE is 'auto1' for 1D images, and 'auto2' for % 2D images. % % GAP (optional, default=1) specifies the gap in pixels to leave % between subbands (2D images only). % % LEVEL_SCALE_FACTOR indicates the relative scaling between pyramid % levels. This should be set to the sum of the kernel taps of the % lowpass filter used to construct the pyramid (default assumes % L2-normalized filters, using a value of 2 for 2D images, sqrt(2) for % 1D images). % Eero Simoncelli, 2/97. function [range] = showWpyr(pyr, pind, range, gap, scale); % Determine 1D or 2D pyramid: if ((pind(1,1) == 1) | (pind(1,2) ==1)) nbands = 1; else nbands = 3; end %------------------------------------------------------------ %% OPTIONAL ARGS: if (exist('range') ~= 1) if (nbands==1) range = 'auto1'; else range = 'auto2'; end end if (exist('gap') ~= 1) gap = 1; end if (exist('scale') ~= 1) if (nbands == 1) scale = sqrt(2); else scale = 2; end end %------------------------------------------------------------ ht = wpyrHt(pind); nind = size(pind,1); %% Auto range calculations: if strcmp(range,'auto1') range = zeros(nind,1); mn = 0.0; mx = 0.0; for lnum = 1:ht for bnum = 1:nbands band = wpyrBand(pyr,pind,lnum,bnum)/(scale^(lnum-1)); range((lnum-1)*nbands+bnum) = scale^(lnum-1); [bmn,bmx] = range2(band); mn = min(mn, bmn); mx = max(mx, bmx); end end if (nbands == 1) pad = (mx-mn)/12; % *** MAGIC NUMBER!! mn = mn-pad; mx = mx+pad; end range = range * [mn mx]; % outer product band = pyrLow(pyr,pind); [mn,mx] = range2(band); if (nbands == 1) pad = (mx-mn)/12; % *** MAGIC NUMBER!! mn = mn-pad; mx = mx+pad; end range(nind,:) = [mn, mx]; elseif strcmp(range,'indep1') range = zeros(nind,2); for bnum = 1:nind band = pyrBand(pyr,pind,bnum); [mn,mx] = range2(band); if (nbands == 1) pad = (mx-mn)/12; % *** MAGIC NUMBER!! mn = mn-pad; mx = mx+pad; end range(bnum,:) = [mn mx]; end elseif strcmp(range,'auto2') range = zeros(nind,1); sqsum = 0; numpixels = 0; for lnum = 1:ht for bnum = 1:nbands band = wpyrBand(pyr,pind,lnum,bnum)/(scale^(lnum-1)); sqsum = sqsum + sum(sum(band.^2)); numpixels = numpixels + prod(size(band)); range((lnum-1)*nbands+bnum) = scale^(lnum-1); end end stdev = sqrt(sqsum/(numpixels-1)); range = range * [ -3*stdev 3*stdev ]; % outer product band = pyrLow(pyr,pind); av = mean2(band); stdev = sqrt(var2(band)); range(nind,:) = [av-2*stdev,av+2*stdev]; elseif strcmp(range,'indep2') range = zeros(nind,2); for bnum = 1:(nind-1) band = pyrBand(pyr,pind,bnum); stdev = sqrt(var2(band)); range(bnum,:) = [ -3*stdev 3*stdev ]; end band = pyrLow(pyr,pind); av = mean2(band); stdev = sqrt(var2(band)); range(nind,:) = [av-2*stdev,av+2*stdev]; elseif isstr(range) error(sprintf('Bad RANGE argument: %s',range)) elseif ((size(range,1) == 1) & (size(range,2) == 2)) scales = scale.^[0:ht]; if (nbands ~= 1) scales = [scales; scales; scales]; end range = scales(:) * range; % outer product band = pyrLow(pyr,pind); range(nind,:) = range(nind,:) + mean2(band) - mean(range(nind,:)); end % CLEAR FIGURE: clf; if (nbands == 1) %%%%% 1D signal: for bnum=1:nind band = pyrBand(pyr,pind,bnum); subplot(nind,1,nind-bnum+1); plot(band); axis([1, prod(size(band)), range(bnum,:)]); end else %%%%% 2D signal: colormap(gray); cmap = get(gcf,'Colormap'); nshades = size(cmap,1); % Find background color index: clr = get(gcf,'Color'); bg = 1; dist = norm(cmap(bg,:)-clr); for n = 1:nshades ndist = norm(cmap(n,:)-clr); if (ndist < dist) dist = ndist; bg = n; end end %% Compute positions of subbands: llpos = ones(nind,2); for lnum = 1:ht ind1 = nbands*(lnum-1) + 1; xpos = pind(ind1,2) + 1 + gap*(ht-lnum+1); ypos = pind(ind1+1,1) + 1 + gap*(ht-lnum+1); llpos(ind1:ind1+2,:) = [ypos 1; 1 xpos; ypos xpos]; end llpos(nind,:) = [1 1]; %lowpass %% Make position list positive, and allocate appropriate image: llpos = llpos - ones(nind,1)*min(llpos) + 1; urpos = llpos + pind - 1; d_im = bg + zeros(max(urpos)); %% Paste bands into image, (im-r1)*(nshades-1)/(r2-r1) + 1.5 for bnum=1:nind mult = (nshades-1) / (range(bnum,2)-range(bnum,1)); d_im(llpos(bnum,1):urpos(bnum,1), llpos(bnum,2):urpos(bnum,2)) = ... mult*pyrBand(pyr,pind,bnum) + (1.5-mult*range(bnum,1)); end hh = image(d_im); axis('off'); pixelAxes(size(d_im),'full'); set(hh,'UserData',range); end
github
jbhuang0604/LapSRN-master
imGradient.m
.m
LapSRN-master/utils/matlabPyrTools/imGradient.m
1,547
utf_8
b13a85bea09c3f4e0c1e6140c9a31f7a
% [dx, dy] = imGradient(im, edges) % % Compute the gradient of the image using smooth derivative filters % optimized for accurate direction estimation. Coordinate system % corresponds to standard pixel indexing: X axis points rightward. Y % axis points downward. EDGES specify boundary handling (see corrDn % for options). % % Unlike matlab's new gradient function, which is based on local % differences, this function computes derivatives using 5x5 filters % designed to accurately reflect the local orientation content. % EPS, 1997. % original filters from Int'l Conf Image Processing, 1994. % updated filters 10/2003: see Farid & Simoncelli, IEEE Trans Image Processing, 13(4):496-508, April 2004. % Incorporated into matlabPyrTools 10/2004. function [dx, dy] = imGradient(im, edges) if (exist('edges') ~= 1) edges = 'dont-compute'; end %% kernels from Farid & Simoncelli, IEEE Trans Image Processing, 13(4):496-508, April 2004. gp = [0.037659 0.249153 0.426375 0.249153 0.037659]'; gd = [-0.109604 -0.276691 0.000000 0.276691 0.109604]'; dx = corrDn(corrDn(im, gp, edges), gd', edges); dy = corrDn(corrDn(im, gd, edges), gp', edges); return %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% TEST: %%Make a ramp with random slope and direction dir = 2*pi*rand - pi; slope = 10*rand; sz = 32 im = mkRamp(sz, dir, slope); [dx,dy] = imGradient(im); showIm(dx + sqrt(-1)*dy); ctr = (sz*sz/2)+sz/2; slopeEst = sqrt(dx(ctr).^2 + dy(ctr).^2); dirEst = atan2(dy(ctr), dx(ctr)); [slope, slopeEst] [dir, dirEst]
github
jbhuang0604/LapSRN-master
lpyrHt.m
.m
LapSRN-master/utils/matlabPyrTools/lpyrHt.m
233
utf_8
dd0b45926abda2b3fe9aaec0a4f4d214
% [HEIGHT] = lpyrHt(INDICES) % % Compute height of Laplacian pyramid with given its INDICES matrix. % See buildLpyr.m % Eero Simoncelli, 6/96. function [ht] = lpyrHt(pind) % Don't count lowpass residual band ht = size(pind,1)-1;
github
jbhuang0604/LapSRN-master
buildGpyr.m
.m
LapSRN-master/utils/matlabPyrTools/buildGpyr.m
1,931
utf_8
3f1cfe5507fe34b51d71a87d955abbf5
% [PYR, INDICES] = buildGpyr(IM, HEIGHT, FILT, EDGES) % % Construct a Gaussian pyramid on matrix IM. % % HEIGHT (optional) specifies the number of pyramid levels to build. Default % is 1+maxPyrHt(size(IM),size(FILT)). % You can also specify 'auto' to use this value. % % FILT (optional) can be a string naming a standard filter (see % namedFilter), or a vector which will be used for (separable) % convolution. Default = 'binom5'. EDGES specifies edge-handling, and % defaults to 'reflect1' (see corrDn). % % PYR is a vector containing the N pyramid subbands, ordered from fine % to coarse. INDICES is an Nx2 matrix containing the sizes of % each subband. This is compatible with the MatLab Wavelet toolbox. % Eero Simoncelli, 6/96. function [pyr,pind] = buildGpyr(im, ht, filt, edges) if (nargin < 1) error('First argument (IM) is required'); end im_sz = size(im); %------------------------------------------------------------ %% OPTIONAL ARGS: if (exist('filt') ~= 1) filt = 'binom5'; end if isstr(filt) filt = namedFilter(filt); end if ( (size(filt,1) > 1) & (size(filt,2) > 1) ) error('FILT should be a 1D filter (i.e., a vector)'); else filt = filt(:); end max_ht = 1 + maxPyrHt(im_sz, size(filt,1)); if ( (exist('ht') ~= 1) | (ht == 'auto') ) ht = max_ht; else if (ht > max_ht) error(sprintf('Cannot build pyramid higher than %d levels.',max_ht)); end end if (exist('edges') ~= 1) edges= 'reflect1'; end %------------------------------------------------------------ if (ht <= 1) pyr = im(:); pind = im_sz; else if (im_sz(2) == 1) lo2 = corrDn(im, filt, edges, [2 1], [1 1]); elseif (im_sz(1) == 1) lo2 = corrDn(im, filt', edges, [1 2], [1 1]); else lo = corrDn(im, filt', edges, [1 2], [1 1]); lo2 = corrDn(lo, filt, edges, [2 1], [1 1]); end [npyr,nind] = buildGpyr(lo2, ht-1, filt, edges); pyr = [im(:); npyr]; pind = [im_sz; nind]; end
github
jbhuang0604/LapSRN-master
shift.m
.m
LapSRN-master/utils/matlabPyrTools/shift.m
438
utf_8
2ac42b171e4ca683ef1d361eaf331870
% [RES] = shift(MTX, OFFSET) % % Circular shift 2D matrix samples by OFFSET (a [Y,X] 2-vector), % such that RES(POS) = MTX(POS-OFFSET). function res = shift(mtx, offset) dims = size(mtx); offset = mod(-offset,dims); res = [ mtx(offset(1)+1:dims(1), offset(2)+1:dims(2)), ... mtx(offset(1)+1:dims(1), 1:offset(2)); ... mtx(1:offset(1), offset(2)+1:dims(2)), ... mtx(1:offset(1), 1:offset(2)) ];
github
jbhuang0604/LapSRN-master
namedFilter.m
.m
LapSRN-master/utils/matlabPyrTools/namedFilter.m
3,207
utf_8
8f45ef65fca60f53e0f734c4f1ae01bf
% KERNEL = NAMED_FILTER(NAME) % % Some standard 1D filter kernels. These are scaled such that % their L2-norm is 1.0. % % binomN - binomial coefficient filter of order N-1 % haar: - Haar wavelet. % qmf8, qmf12, qmf16 - Symmetric Quadrature Mirror Filters [Johnston80] % daub2,daub3,daub4 - Daubechies wavelet [Daubechies88]. % qmf5, qmf9, qmf13: - Symmetric Quadrature Mirror Filters [Simoncelli88,Simoncelli90] % % See bottom of file for full citations. % Eero Simoncelli, 6/96. function [kernel] = named_filter(name) if strcmp(name(1:min(5,size(name,2))), 'binom') kernel = sqrt(2) * binomialFilter(str2num(name(6:size(name,2)))); elseif strcmp(name,'qmf5') kernel = [-0.076103 0.3535534 0.8593118 0.3535534 -0.076103]'; elseif strcmp(name,'qmf9') kernel = [0.02807382 -0.060944743 -0.073386624 0.41472545 0.7973934 ... 0.41472545 -0.073386624 -0.060944743 0.02807382]'; elseif strcmp(name,'qmf13') kernel = [-0.014556438 0.021651438 0.039045125 -0.09800052 ... -0.057827797 0.42995453 0.7737113 0.42995453 -0.057827797 ... -0.09800052 0.039045125 0.021651438 -0.014556438]'; elseif strcmp(name,'qmf8') kernel = sqrt(2) * [0.00938715 -0.07065183 0.06942827 0.4899808 ... 0.4899808 0.06942827 -0.07065183 0.00938715 ]'; elseif strcmp(name,'qmf12') kernel = sqrt(2) * [-0.003809699 0.01885659 -0.002710326 -0.08469594 ... 0.08846992 0.4843894 0.4843894 0.08846992 -0.08469594 -0.002710326 ... 0.01885659 -0.003809699 ]'; elseif strcmp(name,'qmf16') kernel = sqrt(2) * [0.001050167 -0.005054526 -0.002589756 0.0276414 -0.009666376 ... -0.09039223 0.09779817 0.4810284 0.4810284 0.09779817 -0.09039223 -0.009666376 ... 0.0276414 -0.002589756 -0.005054526 0.001050167 ]'; elseif strcmp(name,'haar') kernel = [1 1]' / sqrt(2); elseif strcmp(name,'daub2') kernel = [0.482962913145 0.836516303738 0.224143868042 -0.129409522551]'; elseif strcmp(name,'daub3') kernel = [0.332670552950 0.806891509311 0.459877502118 -0.135011020010 ... -0.085441273882 0.035226291882]'; elseif strcmp(name,'daub4') kernel = [0.230377813309 0.714846570553 0.630880767930 -0.027983769417 ... -0.187034811719 0.030841381836 0.032883011667 -0.010597401785]'; elseif strcmp(name,'gauss5') % for backward-compatibility kernel = sqrt(2) * [0.0625 0.25 0.375 0.25 0.0625]'; elseif strcmp(name,'gauss3') % for backward-compatibility kernel = sqrt(2) * [0.25 0.5 0.25]'; else error(sprintf('Bad filter name: %s\n',name)); end % [Johnston80] - J D Johnston, "A filter family designed for use in quadrature % mirror filter banks", Proc. ICASSP, pp 291-294, 1980. % % [Daubechies88] - I Daubechies, "Orthonormal bases of compactly supported wavelets", % Commun. Pure Appl. Math, vol. 42, pp 909-996, 1988. % % [Simoncelli88] - E P Simoncelli, "Orthogonal sub-band image transforms", % PhD Thesis, MIT Dept. of Elec. Eng. and Comp. Sci. May 1988. % Also available as: MIT Media Laboratory Vision and Modeling Technical % Report #100. % % [Simoncelli90] - E P Simoncelli and E H Adelson, "Subband image coding", % Subband Transforms, chapter 4, ed. John W Woods, Kluwer Academic % Publishers, Norwell, MA, 1990, pp 143--192.
github
jbhuang0604/LapSRN-master
buildLpyr.m
.m
LapSRN-master/utils/matlabPyrTools/buildLpyr.m
2,632
utf_8
b62aad457634fd598b373448741860cd
% [PYR, INDICES] = buildLpyr(IM, HEIGHT, FILT1, FILT2, EDGES) % % Construct a Laplacian pyramid on matrix (or vector) IM. % % HEIGHT (optional) specifies the number of pyramid levels to build. Default % is 1+maxPyrHt(size(IM),size(FILT)). You can also specify 'auto' to % use this value. % % FILT1 (optional) can be a string naming a standard filter (see % namedFilter), or a vector which will be used for (separable) % convolution. Default = 'binom5'. FILT2 specifies the "expansion" % filter (default = filt1). EDGES specifies edge-handling, and % defaults to 'reflect1' (see corrDn). % % PYR is a vector containing the N pyramid subbands, ordered from fine % to coarse. INDICES is an Nx2 matrix containing the sizes of % each subband. This is compatible with the MatLab Wavelet toolbox. % Eero Simoncelli, 6/96. function [pyr,pind] = buildLpyr(im, ht, filt1, filt2, edges) if (nargin < 1) error('First argument (IM) is required'); end im_sz = size(im); %------------------------------------------------------------ %% OPTIONAL ARGS: if (exist('filt1') ~= 1) filt1 = 'binom5'; end if isstr(filt1) filt1 = namedFilter(filt1); end if ( (size(filt1,1) > 1) & (size(filt1,2) > 1) ) error('FILT1 should be a 1D filter (i.e., a vector)'); else filt1 = filt1(:); end if (exist('filt2') ~= 1) filt2 = filt1; end if isstr(filt2) filt2 = namedFilter(filt2); end if ( (size(filt2,1) > 1) & (size(filt2,2) > 1) ) error('FILT2 should be a 1D filter (i.e., a vector)'); else filt2 = filt2(:); end max_ht = 1 + maxPyrHt(im_sz, max(size(filt1,1), size(filt2,1))); if ( (exist('ht') ~= 1) | (ht == 'auto') ) ht = max_ht; else if (ht > max_ht) error(sprintf('Cannot build pyramid higher than %d levels.',max_ht)); end end if (exist('edges') ~= 1) edges= 'reflect1'; end %------------------------------------------------------------ if (ht <= 1) pyr = im(:); pind = im_sz; else if (im_sz(2) == 1) lo2 = corrDn(im, filt1, edges, [2 1], [1 1]); elseif (im_sz(1) == 1) lo2 = corrDn(im, filt1', edges, [1 2], [1 1]); else lo = corrDn(im, filt1', edges, [1 2], [1 1]); int_sz = size(lo); lo2 = corrDn(lo, filt1, edges, [2 1], [1 1]); end [npyr,nind] = buildLpyr(lo2, ht-1, filt1, filt2, edges); if (im_sz(1) == 1) hi2 = upConv(lo2, filt2', edges, [1 2], [1 1], im_sz); elseif (im_sz(2) == 1) hi2 = upConv(lo2, filt2, edges, [2 1], [1 1], im_sz); else hi = upConv(lo2, filt2, edges, [2 1], [1 1], int_sz); hi2 = upConv(hi, filt2', edges, [1 2], [1 1], im_sz); end hi2 = im - hi2; pyr = [hi2(:); npyr]; pind = [im_sz; nind]; end
github
jbhuang0604/LapSRN-master
mkAngle.m
.m
LapSRN-master/utils/matlabPyrTools/mkAngle.m
788
utf_8
126297224256c6e9077dc58f4094c39a
% IM = mkAngle(SIZE, PHASE, ORIGIN) % % Compute a matrix of dimension SIZE (a [Y X] 2-vector, or a scalar) % containing samples of the polar angle (in radians, CW from the % X-axis, ranging from -pi to pi), relative to angle PHASE (default = % 0), about ORIGIN pixel (default = (size+1)/2). % Eero Simoncelli, 6/96. function [res] = mkAngle(sz, phase, origin) sz = sz(:); if (size(sz,1) == 1) sz = [sz,sz]; end % ----------------------------------------------------------------- % OPTIONAL args: if (exist('origin') ~= 1) origin = (sz+1)/2; end % ----------------------------------------------------------------- [xramp,yramp] = meshgrid( [1:sz(2)]-origin(2), [1:sz(1)]-origin(1) ); res = atan2(yramp,xramp); if (exist('phase') == 1) res = mod(res+(pi-phase),2*pi)-pi; end
github
jbhuang0604/LapSRN-master
wpyrHt.m
.m
LapSRN-master/utils/matlabPyrTools/wpyrHt.m
270
utf_8
18e1a724afee99389db70484333eb05a
% [HEIGHT] = wpyrHt(INDICES) % % Compute height of separable QMF/wavelet pyramid with given index matrix. % Eero Simoncelli, 6/96. function [ht] = wpyrHt(pind) if ((pind(1,1) == 1) | (pind(1,2) ==1)) nbands = 1; else nbands = 3; end ht = (size(pind,1)-1)/nbands;
github
jbhuang0604/LapSRN-master
sp0Filters.m
.m
LapSRN-master/utils/matlabPyrTools/sp0Filters.m
6,140
utf_8
0c5cd7bafff21efacd2a8ec71af90f49
% Steerable pyramid filters. Transform described in: % % @INPROCEEDINGS{Simoncelli95b, % TITLE = "The Steerable Pyramid: A Flexible Architecture for % Multi-Scale Derivative Computation", % AUTHOR = "E P Simoncelli and W T Freeman", % BOOKTITLE = "Second Int'l Conf on Image Processing", % ADDRESS = "Washington, DC", MONTH = "October", YEAR = 1995 } % % Filter kernel design described in: % %@INPROCEEDINGS{Karasaridis96, % TITLE = "A Filter Design Technique for % Steerable Pyramid Image Transforms", % AUTHOR = "A Karasaridis and E P Simoncelli", % BOOKTITLE = "ICASSP", ADDRESS = "Atlanta, GA", % MONTH = "May", YEAR = 1996 } % Eero Simoncelli, 6/96. function [lo0filt,hi0filt,lofilt,bfilts,mtx,harmonics] = sp0Filters(); harmonics = [ 0 ]; lo0filt = [ ... -4.514000e-04 -1.137100e-04 -3.725800e-04 -3.743860e-03 -3.725800e-04 -1.137100e-04 -4.514000e-04 -1.137100e-04 -6.119520e-03 -1.344160e-02 -7.563200e-03 -1.344160e-02 -6.119520e-03 -1.137100e-04 -3.725800e-04 -1.344160e-02 6.441488e-02 1.524935e-01 6.441488e-02 -1.344160e-02 -3.725800e-04 -3.743860e-03 -7.563200e-03 1.524935e-01 3.153017e-01 1.524935e-01 -7.563200e-03 -3.743860e-03 -3.725800e-04 -1.344160e-02 6.441488e-02 1.524935e-01 6.441488e-02 -1.344160e-02 -3.725800e-04 -1.137100e-04 -6.119520e-03 -1.344160e-02 -7.563200e-03 -1.344160e-02 -6.119520e-03 -1.137100e-04 -4.514000e-04 -1.137100e-04 -3.725800e-04 -3.743860e-03 -3.725800e-04 -1.137100e-04 -4.514000e-04]; lofilt = [ ... -2.257000e-04 -8.064400e-04 -5.686000e-05 8.741400e-04 -1.862800e-04 -1.031640e-03 -1.871920e-03 -1.031640e-03 -1.862800e-04 8.741400e-04 -5.686000e-05 -8.064400e-04 -2.257000e-04 -8.064400e-04 1.417620e-03 -1.903800e-04 -2.449060e-03 -4.596420e-03 -7.006740e-03 -6.948900e-03 -7.006740e-03 -4.596420e-03 -2.449060e-03 -1.903800e-04 1.417620e-03 -8.064400e-04 -5.686000e-05 -1.903800e-04 -3.059760e-03 -6.401000e-03 -6.720800e-03 -5.236180e-03 -3.781600e-03 -5.236180e-03 -6.720800e-03 -6.401000e-03 -3.059760e-03 -1.903800e-04 -5.686000e-05 8.741400e-04 -2.449060e-03 -6.401000e-03 -5.260020e-03 3.938620e-03 1.722078e-02 2.449600e-02 1.722078e-02 3.938620e-03 -5.260020e-03 -6.401000e-03 -2.449060e-03 8.741400e-04 -1.862800e-04 -4.596420e-03 -6.720800e-03 3.938620e-03 3.220744e-02 6.306262e-02 7.624674e-02 6.306262e-02 3.220744e-02 3.938620e-03 -6.720800e-03 -4.596420e-03 -1.862800e-04 -1.031640e-03 -7.006740e-03 -5.236180e-03 1.722078e-02 6.306262e-02 1.116388e-01 1.348999e-01 1.116388e-01 6.306262e-02 1.722078e-02 -5.236180e-03 -7.006740e-03 -1.031640e-03 -1.871920e-03 -6.948900e-03 -3.781600e-03 2.449600e-02 7.624674e-02 1.348999e-01 1.576508e-01 1.348999e-01 7.624674e-02 2.449600e-02 -3.781600e-03 -6.948900e-03 -1.871920e-03 -1.031640e-03 -7.006740e-03 -5.236180e-03 1.722078e-02 6.306262e-02 1.116388e-01 1.348999e-01 1.116388e-01 6.306262e-02 1.722078e-02 -5.236180e-03 -7.006740e-03 -1.031640e-03 -1.862800e-04 -4.596420e-03 -6.720800e-03 3.938620e-03 3.220744e-02 6.306262e-02 7.624674e-02 6.306262e-02 3.220744e-02 3.938620e-03 -6.720800e-03 -4.596420e-03 -1.862800e-04 8.741400e-04 -2.449060e-03 -6.401000e-03 -5.260020e-03 3.938620e-03 1.722078e-02 2.449600e-02 1.722078e-02 3.938620e-03 -5.260020e-03 -6.401000e-03 -2.449060e-03 8.741400e-04 -5.686000e-05 -1.903800e-04 -3.059760e-03 -6.401000e-03 -6.720800e-03 -5.236180e-03 -3.781600e-03 -5.236180e-03 -6.720800e-03 -6.401000e-03 -3.059760e-03 -1.903800e-04 -5.686000e-05 -8.064400e-04 1.417620e-03 -1.903800e-04 -2.449060e-03 -4.596420e-03 -7.006740e-03 -6.948900e-03 -7.006740e-03 -4.596420e-03 -2.449060e-03 -1.903800e-04 1.417620e-03 -8.064400e-04 -2.257000e-04 -8.064400e-04 -5.686000e-05 8.741400e-04 -1.862800e-04 -1.031640e-03 -1.871920e-03 -1.031640e-03 -1.862800e-04 8.741400e-04 -5.686000e-05 -8.064400e-04 -2.257000e-04]; mtx = [ 1.000000 ]; hi0filt = [... 5.997200e-04 -6.068000e-05 -3.324900e-04 -3.325600e-04 -2.406600e-04 -3.325600e-04 -3.324900e-04 -6.068000e-05 5.997200e-04 -6.068000e-05 1.263100e-04 4.927100e-04 1.459700e-04 -3.732100e-04 1.459700e-04 4.927100e-04 1.263100e-04 -6.068000e-05 -3.324900e-04 4.927100e-04 -1.616650e-03 -1.437358e-02 -2.420138e-02 -1.437358e-02 -1.616650e-03 4.927100e-04 -3.324900e-04 -3.325600e-04 1.459700e-04 -1.437358e-02 -6.300923e-02 -9.623594e-02 -6.300923e-02 -1.437358e-02 1.459700e-04 -3.325600e-04 -2.406600e-04 -3.732100e-04 -2.420138e-02 -9.623594e-02 8.554893e-01 -9.623594e-02 -2.420138e-02 -3.732100e-04 -2.406600e-04 -3.325600e-04 1.459700e-04 -1.437358e-02 -6.300923e-02 -9.623594e-02 -6.300923e-02 -1.437358e-02 1.459700e-04 -3.325600e-04 -3.324900e-04 4.927100e-04 -1.616650e-03 -1.437358e-02 -2.420138e-02 -1.437358e-02 -1.616650e-03 4.927100e-04 -3.324900e-04 -6.068000e-05 1.263100e-04 4.927100e-04 1.459700e-04 -3.732100e-04 1.459700e-04 4.927100e-04 1.263100e-04 -6.068000e-05 5.997200e-04 -6.068000e-05 -3.324900e-04 -3.325600e-04 -2.406600e-04 -3.325600e-04 -3.324900e-04 -6.068000e-05 5.997200e-04 ]; bfilts = [ ... -9.066000e-05 -1.738640e-03 -4.942500e-03 -7.889390e-03 -1.009473e-02 -7.889390e-03 -4.942500e-03 -1.738640e-03 -9.066000e-05 ... -1.738640e-03 -4.625150e-03 -7.272540e-03 -7.623410e-03 -9.091950e-03 -7.623410e-03 -7.272540e-03 -4.625150e-03 -1.738640e-03 ... -4.942500e-03 -7.272540e-03 -2.129540e-02 -2.435662e-02 -3.487008e-02 -2.435662e-02 -2.129540e-02 -7.272540e-03 -4.942500e-03 ... -7.889390e-03 -7.623410e-03 -2.435662e-02 -1.730466e-02 -3.158605e-02 -1.730466e-02 -2.435662e-02 -7.623410e-03 -7.889390e-03 ... -1.009473e-02 -9.091950e-03 -3.487008e-02 -3.158605e-02 9.464195e-01 -3.158605e-02 -3.487008e-02 -9.091950e-03 -1.009473e-02 ... -7.889390e-03 -7.623410e-03 -2.435662e-02 -1.730466e-02 -3.158605e-02 -1.730466e-02 -2.435662e-02 -7.623410e-03 -7.889390e-03 ... -4.942500e-03 -7.272540e-03 -2.129540e-02 -2.435662e-02 -3.487008e-02 -2.435662e-02 -2.129540e-02 -7.272540e-03 -4.942500e-03 ... -1.738640e-03 -4.625150e-03 -7.272540e-03 -7.623410e-03 -9.091950e-03 -7.623410e-03 -7.272540e-03 -4.625150e-03 -1.738640e-03 ... -9.066000e-05 -1.738640e-03 -4.942500e-03 -7.889390e-03 -1.009473e-02 -7.889390e-03 -4.942500e-03 -1.738640e-03 -9.066000e-05 ]';
github
jbhuang0604/LapSRN-master
sp5Filters.m
.m
LapSRN-master/utils/matlabPyrTools/sp5Filters.m
6,949
utf_8
305fb0c0ca0709fc34ca6c5b4bb91712
% Steerable pyramid filters. Transform described in: % % @INPROCEEDINGS{Simoncelli95b, % TITLE = "The Steerable Pyramid: A Flexible Architecture for % Multi-Scale Derivative Computation", % AUTHOR = "E P Simoncelli and W T Freeman", % BOOKTITLE = "Second Int'l Conf on Image Processing", % ADDRESS = "Washington, DC", MONTH = "October", YEAR = 1995 } % % Filter kernel design described in: % %@INPROCEEDINGS{Karasaridis96, % TITLE = "A Filter Design Technique for % Steerable Pyramid Image Transforms", % AUTHOR = "A Karasaridis and E P Simoncelli", % BOOKTITLE = "ICASSP", ADDRESS = "Atlanta, GA", % MONTH = "May", YEAR = 1996 } % Eero Simoncelli, 6/96. function [lo0filt,hi0filt,lofilt,bfilts,mtx,harmonics] = sp5Filters(); harmonics = [1 3 5]; mtx = [ ... 0.3333 0.2887 0.1667 0.0000 -0.1667 -0.2887 0.0000 0.1667 0.2887 0.3333 0.2887 0.1667 0.3333 -0.0000 -0.3333 -0.0000 0.3333 -0.0000 0.0000 0.3333 0.0000 -0.3333 0.0000 0.3333 0.3333 -0.2887 0.1667 -0.0000 -0.1667 0.2887 -0.0000 0.1667 -0.2887 0.3333 -0.2887 0.1667]; hi0filt = [ -0.00033429 -0.00113093 -0.00171484 -0.00133542 -0.00080639 -0.00133542 -0.00171484 -0.00113093 -0.00033429 -0.00113093 -0.00350017 -0.00243812 0.00631653 0.01261227 0.00631653 -0.00243812 -0.00350017 -0.00113093 -0.00171484 -0.00243812 -0.00290081 -0.00673482 -0.00981051 -0.00673482 -0.00290081 -0.00243812 -0.00171484 -0.00133542 0.00631653 -0.00673482 -0.07027679 -0.11435863 -0.07027679 -0.00673482 0.00631653 -0.00133542 -0.00080639 0.01261227 -0.00981051 -0.11435863 0.81380200 -0.11435863 -0.00981051 0.01261227 -0.00080639 -0.00133542 0.00631653 -0.00673482 -0.07027679 -0.11435863 -0.07027679 -0.00673482 0.00631653 -0.00133542 -0.00171484 -0.00243812 -0.00290081 -0.00673482 -0.00981051 -0.00673482 -0.00290081 -0.00243812 -0.00171484 -0.00113093 -0.00350017 -0.00243812 0.00631653 0.01261227 0.00631653 -0.00243812 -0.00350017 -0.00113093 -0.00033429 -0.00113093 -0.00171484 -0.00133542 -0.00080639 -0.00133542 -0.00171484 -0.00113093 -0.00033429]; lo0filt = [ 0.00341614 -0.01551246 -0.03848215 -0.01551246 0.00341614 -0.01551246 0.05586982 0.15925570 0.05586982 -0.01551246 -0.03848215 0.15925570 0.40304148 0.15925570 -0.03848215 -0.01551246 0.05586982 0.15925570 0.05586982 -0.01551246 0.00341614 -0.01551246 -0.03848215 -0.01551246 0.00341614]; lofilt = 2*[ 0.00085404 -0.00244917 -0.00387812 -0.00944432 -0.00962054 -0.00944432 -0.00387812 -0.00244917 0.00085404 -0.00244917 -0.00523281 -0.00661117 0.00410600 0.01002988 0.00410600 -0.00661117 -0.00523281 -0.00244917 -0.00387812 -0.00661117 0.01396746 0.03277038 0.03981393 0.03277038 0.01396746 -0.00661117 -0.00387812 -0.00944432 0.00410600 0.03277038 0.06426333 0.08169618 0.06426333 0.03277038 0.00410600 -0.00944432 -0.00962054 0.01002988 0.03981393 0.08169618 0.10096540 0.08169618 0.03981393 0.01002988 -0.00962054 -0.00944432 0.00410600 0.03277038 0.06426333 0.08169618 0.06426333 0.03277038 0.00410600 -0.00944432 -0.00387812 -0.00661117 0.01396746 0.03277038 0.03981393 0.03277038 0.01396746 -0.00661117 -0.00387812 -0.00244917 -0.00523281 -0.00661117 0.00410600 0.01002988 0.00410600 -0.00661117 -0.00523281 -0.00244917 0.00085404 -0.00244917 -0.00387812 -0.00944432 -0.00962054 -0.00944432 -0.00387812 -0.00244917 0.00085404]; bfilts = [... 0.00277643 0.00496194 0.01026699 0.01455399 0.01026699 0.00496194 0.00277643 ... -0.00986904 -0.00893064 0.01189859 0.02755155 0.01189859 -0.00893064 -0.00986904 ... -0.01021852 -0.03075356 -0.08226445 -0.11732297 -0.08226445 -0.03075356 -0.01021852 ... 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 ... 0.01021852 0.03075356 0.08226445 0.11732297 0.08226445 0.03075356 0.01021852 ... 0.00986904 0.00893064 -0.01189859 -0.02755155 -0.01189859 0.00893064 0.00986904 ... -0.00277643 -0.00496194 -0.01026699 -0.01455399 -0.01026699 -0.00496194 -0.00277643; ... -0.00343249 -0.00640815 -0.00073141 0.01124321 0.00182078 0.00285723 0.01166982 ... -0.00358461 -0.01977507 -0.04084211 -0.00228219 0.03930573 0.01161195 0.00128000 ... 0.01047717 0.01486305 -0.04819057 -0.12227230 -0.05394139 0.00853965 -0.00459034 ... 0.00790407 0.04435647 0.09454202 -0.00000000 -0.09454202 -0.04435647 -0.00790407 ... 0.00459034 -0.00853965 0.05394139 0.12227230 0.04819057 -0.01486305 -0.01047717 ... -0.00128000 -0.01161195 -0.03930573 0.00228219 0.04084211 0.01977507 0.00358461 ... -0.01166982 -0.00285723 -0.00182078 -0.01124321 0.00073141 0.00640815 0.00343249; ... 0.00343249 0.00358461 -0.01047717 -0.00790407 -0.00459034 0.00128000 0.01166982 ... 0.00640815 0.01977507 -0.01486305 -0.04435647 0.00853965 0.01161195 0.00285723 ... 0.00073141 0.04084211 0.04819057 -0.09454202 -0.05394139 0.03930573 0.00182078 ... -0.01124321 0.00228219 0.12227230 -0.00000000 -0.12227230 -0.00228219 0.01124321 ... -0.00182078 -0.03930573 0.05394139 0.09454202 -0.04819057 -0.04084211 -0.00073141 ... -0.00285723 -0.01161195 -0.00853965 0.04435647 0.01486305 -0.01977507 -0.00640815 ... -0.01166982 -0.00128000 0.00459034 0.00790407 0.01047717 -0.00358461 -0.00343249; ... -0.00277643 0.00986904 0.01021852 -0.00000000 -0.01021852 -0.00986904 0.00277643 ... -0.00496194 0.00893064 0.03075356 -0.00000000 -0.03075356 -0.00893064 0.00496194 ... -0.01026699 -0.01189859 0.08226445 -0.00000000 -0.08226445 0.01189859 0.01026699 ... -0.01455399 -0.02755155 0.11732297 -0.00000000 -0.11732297 0.02755155 0.01455399 ... -0.01026699 -0.01189859 0.08226445 -0.00000000 -0.08226445 0.01189859 0.01026699 ... -0.00496194 0.00893064 0.03075356 -0.00000000 -0.03075356 -0.00893064 0.00496194 ... -0.00277643 0.00986904 0.01021852 -0.00000000 -0.01021852 -0.00986904 0.00277643; ... -0.01166982 -0.00128000 0.00459034 0.00790407 0.01047717 -0.00358461 -0.00343249 ... -0.00285723 -0.01161195 -0.00853965 0.04435647 0.01486305 -0.01977507 -0.00640815 ... -0.00182078 -0.03930573 0.05394139 0.09454202 -0.04819057 -0.04084211 -0.00073141 ... -0.01124321 0.00228219 0.12227230 -0.00000000 -0.12227230 -0.00228219 0.01124321 ... 0.00073141 0.04084211 0.04819057 -0.09454202 -0.05394139 0.03930573 0.00182078 ... 0.00640815 0.01977507 -0.01486305 -0.04435647 0.00853965 0.01161195 0.00285723 ... 0.00343249 0.00358461 -0.01047717 -0.00790407 -0.00459034 0.00128000 0.01166982; ... -0.01166982 -0.00285723 -0.00182078 -0.01124321 0.00073141 0.00640815 0.00343249 ... -0.00128000 -0.01161195 -0.03930573 0.00228219 0.04084211 0.01977507 0.00358461 ... 0.00459034 -0.00853965 0.05394139 0.12227230 0.04819057 -0.01486305 -0.01047717 ... 0.00790407 0.04435647 0.09454202 -0.00000000 -0.09454202 -0.04435647 -0.00790407 ... 0.01047717 0.01486305 -0.04819057 -0.12227230 -0.05394139 0.00853965 -0.00459034 ... -0.00358461 -0.01977507 -0.04084211 -0.00228219 0.03930573 0.01161195 0.00128000 ... -0.00343249 -0.00640815 -0.00073141 0.01124321 0.00182078 0.00285723 0.01166982]';
github
jbhuang0604/LapSRN-master
steer.m
.m
LapSRN-master/utils/matlabPyrTools/steer.m
1,990
utf_8
3db4dd948e0ece7c7237330b7d4f191e
% RES = STEER(BASIS, ANGLE, HARMONICS, STEERMTX) % % Steer BASIS to the specfied ANGLE. % % BASIS should be a matrix whose columns are vectorized rotated copies of a % steerable function, or the responses of a set of steerable filters. % % ANGLE can be a scalar, or a column vector the size of the basis. % % HARMONICS (optional, default is N even or odd low frequencies, as for % derivative filters) should be a list of harmonic numbers indicating % the angular harmonic content of the basis. % % STEERMTX (optional, default assumes cosine phase harmonic components, % and filter positions at 2pi*n/N) should be a matrix which maps % the filters onto Fourier series components (ordered [cos0 cos1 sin1 % cos2 sin2 ... sinN]). See steer2HarmMtx.m % Eero Simoncelli, 7/96. function res = steer(basis,angle,harmonics,steermtx) num = size(basis,2); if ( any(size(angle) ~= [size(basis,1) 1]) & any(size(angle) ~= [1 1]) ) error('ANGLE must be a scalar, or a column vector the size of the basis elements'); end %% If HARMONICS are not passed, assume derivatives. if (exist('harmonics') ~= 1) if (mod(num,2) == 0) harmonics = [0:(num/2)-1]'*2 + 1; else harmonics = [0:(num-1)/2]'*2; end else harmonics = harmonics(:); if ((2*size(harmonics,1)-any(harmonics == 0)) ~= num) error('harmonics list is incompatible with basis size'); end end %% If STEERMTX not passed, assume evenly distributed cosine-phase filters: if (exist('steermtx') ~= 1) steermtx = steer2HarmMtx(harmonics, pi*[0:num-1]/num, 'even'); end steervect = zeros(size(angle,1),num); arg = angle * harmonics(find(harmonics~=0))'; if (all(harmonics)) steervect(:, 1:2:num) = cos(arg); steervect(:, 2:2:num) = sin(arg); else steervect(:, 1) = ones(size(arg,1),1); steervect(:, 2:2:num) = cos(arg); steervect(:, 3:2:num) = sin(arg); end steervect = steervect * steermtx; if (size(steervect,1) > 1) tmp = basis' .* steervect'; res = sum(tmp)'; else res = basis * steervect'; end
github
jbhuang0604/LapSRN-master
mkGaussian.m
.m
LapSRN-master/utils/matlabPyrTools/mkGaussian.m
1,565
utf_8
1f55e73fbc9155a38607b0667da2d7f3
% IM = mkGaussian(SIZE, COVARIANCE, MEAN, AMPLITUDE) % % Compute a matrix with dimensions SIZE (a [Y X] 2-vector, or a % scalar) containing a Gaussian function, centered at pixel position % specified by MEAN (default = (size+1)/2), with given COVARIANCE (can % be a scalar, 2-vector, or 2x2 matrix. Default = (min(size)/6)^2), % and AMPLITUDE. AMPLITUDE='norm' (default) will produce a % probability-normalized function. All but the first argument are % optional. % Eero Simoncelli, 6/96. function [res] = mkGaussian(sz, cov, mn, ampl) sz = sz(:); if (size(sz,1) == 1) sz = [sz,sz]; end %------------------------------------------------------------ %% OPTIONAL ARGS: if (exist('cov') ~= 1) cov = (min(sz(1),sz(2))/6)^2; end if ( (exist('mn') ~= 1) | isempty(mn) ) mn = (sz+1)/2; else mn = mn(:); if (size(mn,1) == 1) mn = [mn, mn]; end end if (exist('ampl') ~= 1) ampl = 'norm'; end %------------------------------------------------------------ [xramp,yramp] = meshgrid([1:sz(2)]-mn(2),[1:sz(1)]-mn(1)); if (sum(size(cov)) == 2) % scalar if (strcmp(ampl,'norm')) ampl = 1/(2*pi*cov(1)); end e = (xramp.^2 + yramp.^2)/(-2 * cov); elseif (sum(size(cov)) == 3) % a 2-vector if (strcmp(ampl,'norm')) ampl = 1/(2*pi*sqrt(cov(1)*cov(2))); end e = xramp.^2/(-2 * cov(2)) + yramp.^2/(-2 * cov(1)); else if (strcmp(ampl,'norm')) ampl = 1/(2*pi*sqrt(det(cov))); end cov = -inv(cov)/2; e = cov(2,2)*xramp.^2 + (cov(1,2)+cov(2,1))*(xramp.*yramp) ... + cov(1,1)*yramp.^2; end res = ampl .* exp(e);
github
jbhuang0604/LapSRN-master
factorial.m
.m
LapSRN-master/utils/matlabPyrTools/factorial.m
273
utf_8
370971eae7a2351704973c452848d194
%% RES = factorial(NUM) % % Factorial function that works on matrices (matlab's does not). % EPS, 11/02 function res = factorial(num) res = ones(size(num)); ind = find(num > 0); if ( ~isempty(ind) ) subNum = num(ind); res(ind) = subNum .* factorial(subNum-1); end
github
jbhuang0604/LapSRN-master
entropy2.m
.m
LapSRN-master/utils/matlabPyrTools/entropy2.m
693
utf_8
c637630f7ac8912e5cb30f67551aece7
% E = ENTROPY2(MTX,BINSIZE) % % Compute the first-order sample entropy of MTX. Samples of VEC are % first discretized. Optional argument BINSIZE controls the % discretization, and defaults to 256/(max(VEC)-min(VEC)). % % NOTE: This is a heavily biased estimate of entropy (it is too % small) when you don't have much data! % Eero Simoncelli, 6/96. function res = entropy2(mtx,binsize) %% Ensure it's a vector, not a matrix. vec = mtx(:); [mn,mx] = range2(vec); if (exist('binsize') == 1) nbins = max((mx-mn)/binsize, 1); else nbins = 256; end [bincount,bins] = histo(vec,nbins); %% Collect non-zero bins: H = bincount(find(bincount)); H = H/sum(H); res = -sum(H .* log2(H));
github
jbhuang0604/LapSRN-master
buildSFpyr.m
.m
LapSRN-master/utils/matlabPyrTools/buildSFpyr.m
3,256
utf_8
84c0a17ac90df74f317c29833c54ffa3
% [PYR, INDICES, STEERMTX, HARMONICS] = buildSFpyr(IM, HEIGHT, ORDER, TWIDTH) % % Construct a steerable pyramid on matrix IM, in the Fourier domain. % This is similar to buildSpyr, except that: % % + Reconstruction is exact (within floating point errors) % + It can produce any number of orientation bands. % - Typically slower, especially for non-power-of-two sizes. % - Boundary-handling is circular. % % HEIGHT (optional) specifies the number of pyramid levels to build. Default % is maxPyrHt(size(IM),size(FILT)); % % The squared radial functions tile the Fourier plane, with a raised-cosine % falloff. Angular functions are cos(theta-k\pi/(K+1))^K, where K is % the ORDER (one less than the number of orientation bands, default= 3). % % TWIDTH is the width of the transition region of the radial lowpass % function, in octaves (default = 1, which gives a raised cosine for % the bandpass filters). % % PYR is a vector containing the N pyramid subbands, ordered from fine % to coarse. INDICES is an Nx2 matrix containing the sizes of % each subband. This is compatible with the MatLab Wavelet toolbox. % See the function STEER for a description of STEERMTX and HARMONICS. % Eero Simoncelli, 5/97. % See http://www.cns.nyu.edu/~eero/STEERPYR/ for more % information about the Steerable Pyramid image decomposition. function [pyr,pind,steermtx,harmonics] = buildSFpyr(im, ht, order, twidth) %----------------------------------------------------------------- %% DEFAULTS: max_ht = floor(log2(min(size(im)))) - 2; if (exist('ht') ~= 1) ht = max_ht; else if (ht > max_ht) error(sprintf('Cannot build pyramid higher than %d levels.',max_ht)); end end if (exist('order') ~= 1) order = 3; elseif ((order > 15) | (order < 0)) fprintf(1,'Warning: ORDER must be an integer in the range [0,15]. Truncating.\n'); order = min(max(order,0),15); else order = round(order); end nbands = order+1; if (exist('twidth') ~= 1) twidth = 1; elseif (twidth <= 0) fprintf(1,'Warning: TWIDTH must be positive. Setting to 1.\n'); twidth = 1; end %----------------------------------------------------------------- %% Steering stuff: if (mod((nbands),2) == 0) harmonics = [0:(nbands/2)-1]'*2 + 1; else harmonics = [0:(nbands-1)/2]'*2; end steermtx = steer2HarmMtx(harmonics, pi*[0:nbands-1]/nbands, 'even'); %----------------------------------------------------------------- dims = size(im); ctr = ceil((dims+0.5)/2); [xramp,yramp] = meshgrid( ([1:dims(2)]-ctr(2))./(dims(2)/2), ... ([1:dims(1)]-ctr(1))./(dims(1)/2) ); angle = atan2(yramp,xramp); log_rad = sqrt(xramp.^2 + yramp.^2); log_rad(ctr(1),ctr(2)) = log_rad(ctr(1),ctr(2)-1); log_rad = log2(log_rad); %% Radial transition function (a raised cosine in log-frequency): [Xrcos,Yrcos] = rcosFn(twidth,(-twidth/2),[0 1]); Yrcos = sqrt(Yrcos); YIrcos = sqrt(1.0 - Yrcos.^2); lo0mask = pointOp(log_rad, YIrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0); imdft = fftshift(fft2(im)); lo0dft = imdft .* lo0mask; [pyr,pind] = buildSFpyrLevs(lo0dft, log_rad, Xrcos, Yrcos, angle, ht, nbands); hi0mask = pointOp(log_rad, Yrcos, Xrcos(1), Xrcos(2)-Xrcos(1), 0); hi0dft = imdft .* hi0mask; hi0 = ifft2(ifftshift(hi0dft)); pyr = [real(hi0(:)) ; pyr]; pind = [size(hi0); pind];
github
jbhuang0604/LapSRN-master
spyrLev.m
.m
LapSRN-master/utils/matlabPyrTools/spyrLev.m
668
utf_8
8d25ccc2790a62ab21a20cc3d0772706
% [LEV,IND] = spyrLev(PYR,INDICES,LEVEL) % % Access a level from a steerable pyramid. % Return as an SxB matrix, B = number of bands, S = total size of a band. % Also returns an Bx2 matrix containing dimensions of the subbands. % Eero Simoncelli, 6/96. function [lev,ind] = spyrLev(pyr,pind,level) nbands = spyrNumBands(pind); if ((level > spyrHt(pind)) | (level < 1)) error(sprintf('Level number must be in the range [1, %d].', spyrHt(pind))); end firstband = 2 + nbands*(level-1); firstind = 1; for l=1:firstband-1 firstind = firstind + prod(pind(l,:)); end ind = pind(firstband:firstband+nbands-1,:); lev = pyr(firstind:firstind+sum(prod(ind'))-1);
github
jbhuang0604/LapSRN-master
pgmWrite.m
.m
LapSRN-master/utils/matlabPyrTools/pgmWrite.m
3,119
utf_8
6425008296069df51c5c30ee1c011850
% RANGE = pgmWrite(MTX, FILENAME, RANGE, TYPE, COMMENT) % % Write a MatLab matrix to a pgm (graylevel image) file. % This format is accessible from the XV image browsing utility. % % RANGE (optional) is a 2-vector specifying the values that map to % black and white, respectively. Passing a value of 'auto' (default) % sets RANGE=[min,max] (as in MatLab's imagesc). 'auto2' sets % RANGE=[mean-2*stdev, mean+2*stdev]. 'auto3' sets % RANGE=[p1-(p2-p1)/8, p2+(p2-p1)/8], where p1 is the 10th percentile % value of the sorted MATRIX samples, and p2 is the 90th percentile % value. % % TYPE (optional) should be 'raw' or 'ascii'. Defaults to 'raw'. % Hany Farid, Spring '96. Modified by Eero Simoncelli, 6/96. function range = pgmWrite(mtx, fname, range, type, comment ); [fid,msg] = fopen( fname, 'w' ); if (fid == -1) error(msg); end %------------------------------------------------------------ %% optional ARGS: if (exist('range') ~= 1) range = 'auto'; end if (exist('type') ~= 1) type = 'raw'; end %------------------------------------------------------------ %% Automatic range calculation: if (strcmp(range,'auto1') | strcmp(range,'auto')) [mn,mx] = range2(mtx); range = [mn,mx]; elseif strcmp(range,'auto2') stdev = sqrt(var2(mtx)); av = mean2(mtx); range = [av-2*stdev,av+2*stdev]; % MAGIC NUMBER: 2 stdevs elseif strcmp(range, 'auto3') percentile = 0.1; % MAGIC NUMBER: 0<p<0.5 [N,X] = histo(mtx); binsz = X(2)-X(1); N = N+1e-10; % Ensure cumsum will be monotonic for call to interp1 cumN = [0, cumsum(N)]/sum(N); cumX = [X(1)-binsz, X] + (binsz/2); ctrRange = interp1(cumN,cumX, [percentile, 1-percentile]); range = mean(ctrRange) + (ctrRange-mean(ctrRange))/(1-2*percentile); elseif isstr(range) error(sprintf('Bad RANGE argument: %s',range)) end if ((range(2) - range(1)) <= eps) range(1) = range(1) - 0.5; range(2) = range(2) + 0.5; end %%% First line contains ID string: %%% "P1" = ascii bitmap, "P2" = ascii greymap, %%% "P3" = ascii pixmap, "P4" = raw bitmap, %%% "P5" = raw greymap, "P6" = raw pixmap if strcmp(type,'raw') fprintf(fid,'P5\n'); format = 5; elseif strcmp(type,'ascii') fprintf(fid,'P2\n'); format = 2; else error(sprintf('PGMWRITE: Bad type argument: %s',type)); end fprintf(fid,'# MatLab PGMWRITE file, saved %s\n',date); if (exist('comment') == 1) fprintf(fid,'# %s\n', comment); end %%% dimensions fprintf(fid,'%d %d\n',size(mtx,2),size(mtx,1)); %%% Maximum pixel value fprintf(fid,'255\n'); %% MatLab's "fprintf" floors when writing floats, so we compute %% (mtx-r1)*255/(r2-r1)+0.5 mult = (255 / (range(2)-range(1))); mtx = (mult * mtx) + (0.5 - mult * range(1)); mtx = max(-0.5+eps,min(255.5-eps,mtx)); if (format == 2) count = fprintf(fid,'%d ',mtx'); elseif (format == 5) count = fwrite(fid,mtx','uchar'); end fclose(fid); if (count ~= size(mtx,1)*size(mtx,2)) fprintf(1,'Warning: File output terminated early!'); end %%% TEST: % foo = 257*rand(100)-1; % pgmWrite(foo,'foo.pgm',[0 255]); % foo2=pgmRead('foo.pgm'); % size(find((foo2-round(foo))~=0)) % foo(find((foo2-round(foo))~=0))
github
jbhuang0604/LapSRN-master
modulateFlip.m
.m
LapSRN-master/utils/matlabPyrTools/modulateFlip.m
461
utf_8
92f12f8068fcf49b9863851f106a5aa3
% [HFILT] = modulateFlipShift(LFILT) % % QMF/Wavelet highpass filter construction: modulate by (-1)^n, % reverse order (and shift by one, which is handled by the convolution % routines). This is an extension of the original definition of QMF's % (e.g., see Simoncelli90). % Eero Simoncelli, 7/96. function [hfilt] = modulateFlipShift(lfilt) lfilt = lfilt(:); sz = size(lfilt,1); sz2 = ceil(sz/2); ind = [sz:-1:1]'; hfilt = lfilt(ind) .* (-1).^(ind-sz2);
github
jbhuang0604/LapSRN-master
mkFract.m
.m
LapSRN-master/utils/matlabPyrTools/mkFract.m
843
utf_8
f0d97e35133978ade3a5fe34dea5d08a
% IM = mkFract(SIZE, FRACT_DIM) % % Make a matrix of dimensions SIZE (a [Y X] 2-vector, or a scalar) % containing fractal (pink) noise with power spectral density of the % form: 1/f^(5-2*FRACT_DIM). Image variance is normalized to 1.0. % FRACT_DIM defaults to 1.0 % Eero Simoncelli, 6/96. %% TODO: Verify that this matches Mandelbrot defn of fractal dimension. %% Make this more efficient! function res = mkFract(dims, fract_dim) if (exist('fract_dim') ~= 1) fract_dim = 1.0; end res = randn(dims); fres = fft2(res); sz = size(res); ctr = ceil((sz+1)./2); shape = ifftshift(mkR(sz, -(2.5-fract_dim), ctr)); shape(1,1) = 1; %%DC term fres = shape .* fres; fres = ifft2(fres); if (max(max(abs(imag(fres)))) > 1e-10) error('Symmetry error in creating fractal'); else res = real(fres); res = res / sqrt(var2(res)); end
github
jbhuang0604/LapSRN-master
mkSquare.m
.m
LapSRN-master/utils/matlabPyrTools/mkSquare.m
2,344
utf_8
7d9553e391552cd91cdd6d81348404e2
% IM = mkSquare(SIZE, PERIOD, DIRECTION, AMPLITUDE, PHASE, ORIGIN, TWIDTH) % or % IM = mkSine(SIZE, FREQ, AMPLITUDE, PHASE, ORIGIN, TWIDTH) % % Compute a matrix of dimension SIZE (a [Y X] 2-vector, or a scalar) % containing samples of a 2D square wave, with given PERIOD (in % pixels), DIRECTION (radians, CW from X-axis, default = 0), AMPLITUDE % (default = 1), and PHASE (radians, relative to ORIGIN, default = 0). % ORIGIN defaults to the center of the image. TWIDTH specifies width % of raised-cosine edges on the bars of the grating (default = % min(2,period/3)). % % In the second form, FREQ is a 2-vector of frequencies (radians/pixel). % Eero Simoncelli, 6/96. % TODO: Add duty cycle. function [res] = mkSquare(sz, per_freq, dir_amp, amp_phase, phase_orig, orig_twidth, twidth) %------------------------------------------------------------ %% OPTIONAL ARGS: if (prod(size(per_freq)) == 2) frequency = norm(per_freq); direction = atan2(per_freq(1),per_freq(2)); if (exist('dir_amp') == 1) amplitude = dir_amp; else amplitude = 1; end if (exist('amp_phase') == 1) phase = amp_phase; else phase = 0; end if (exist('phase_orig') == 1) origin = phase_orig; end if (exist('orig_twidth') == 1) transition = orig_twidth; else transition = min(2,2*pi/(3*frequency)); end if (exist('twidth') == 1) error('Too many arguments for (second form) of mkSine'); end else frequency = 2*pi/per_freq; if (exist('dir_amp') == 1) direction = dir_amp; else direction = 0; end if (exist('amp_phase') == 1) amplitude = amp_phase; else amplitude = 1; end if (exist('phase_orig') == 1) phase = phase_orig; else phase = 0; end if (exist('orig_twidth') == 1) origin = orig_twidth; end if (exist('twidth') == 1) transition = twidth; else transition = min(2,2*pi/(3*frequency)); end end %------------------------------------------------------------ if (exist('origin') == 1) res = mkRamp(sz, direction, frequency, phase, origin) - pi/2; else res = mkRamp(sz, direction, frequency, phase) - pi/2; end [Xtbl,Ytbl] = rcosFn(transition*frequency,pi/2,[-amplitude amplitude]); res = pointOp(abs(mod(res+pi, 2*pi)-pi),Ytbl,Xtbl(1),Xtbl(2)-Xtbl(1),0); % OLD threshold version: %res = amplitude * (mod(res,2*pi) < pi);
github
jbhuang0604/LapSRN-master
spyrNumBands.m
.m
LapSRN-master/utils/matlabPyrTools/spyrNumBands.m
480
utf_8
4a10cb68438c7dfc197ec00066f48fd4
% [NBANDS] = spyrNumBands(INDICES) % % Compute number of orientation bands in a steerable pyramid with % given index matrix. If the pyramid contains only the highpass and % lowpass bands (i.e., zero levels), returns 0. % Eero Simoncelli, 2/97. function [nbands] = spyrNumBands(pind) if (size(pind,1) == 2) nbands = 0; else % Count number of orientation bands: b = 3; while ((b <= size(pind,1)) & all( pind(b,:) == pind(2,:)) ) b = b+1; end nbands = b-2; end
github
jbhuang0604/LapSRN-master
reconSpyr.m
.m
LapSRN-master/utils/matlabPyrTools/reconSpyr.m
2,671
utf_8
ea9e71a5f8a76eadbe8c1a2472d89344
% RES = reconSpyr(PYR, INDICES, FILTFILE, EDGES, LEVS, BANDS) % % Reconstruct image from its steerable pyramid representation, as created % by buildSpyr. % % PYR is a vector containing the N pyramid subbands, ordered from fine % to coarse. INDICES is an Nx2 matrix containing the sizes of % each subband. This is compatible with the MatLab Wavelet toolbox. % % FILTFILE (optional) should be a string referring to an m-file that returns % the rfilters. examples: sp0Filters, sp1Filters, sp3Filters % (default = 'sp1Filters'). % EDGES specifies edge-handling, and defaults to 'reflect1' (see % corrDn). % % LEVS (optional) should be a list of levels to include, or the string % 'all' (default). 0 corresonds to the residual highpass subband. % 1 corresponds to the finest oriented scale. The lowpass band % corresponds to number spyrHt(INDICES)+1. % % BANDS (optional) should be a list of bands to include, or the string % 'all' (default). 1 = vertical, rest proceeding anti-clockwise. % Eero Simoncelli, 6/96. function res = reconSpyr(pyr, pind, filtfile, edges, levs, bands) %%------------------------------------------------------------ %% DEFAULTS: if (exist('filtfile') ~= 1) filtfile = 'sp1Filters'; end if (exist('edges') ~= 1) edges= 'reflect1'; end if (exist('levs') ~= 1) levs = 'all'; end if (exist('bands') ~= 1) bands = 'all'; end %%------------------------------------------------------------ if (isstr(filtfile) & (exist(filtfile) == 2)) [lo0filt,hi0filt,lofilt,bfilts,steermtx,harmonics] = eval(filtfile); nbands = spyrNumBands(pind); if ((nbands > 0) & (size(bfilts,2) ~= nbands)) error('Number of pyramid bands is inconsistent with filter file'); end else error('filtfile argument must be the name of an M-file containing SPYR filters.'); end maxLev = 1+spyrHt(pind); if strcmp(levs,'all') levs = [0:maxLev]'; else if (any(levs > maxLev) | any(levs < 0)) error(sprintf('Level numbers must be in the range [0, %d].', maxLev)); end levs = levs(:); end if strcmp(bands,'all') bands = [1:nbands]'; else if (any(bands < 1) | any(bands > nbands)) error(sprintf('Band numbers must be in the range [1,3].', nbands)); end bands = bands(:); end if (spyrHt(pind) == 0) if (any(levs==1)) res1 = pyrBand(pyr,pind,2); else res1 = zeros(pind(2,:)); end else res1 = reconSpyrLevs(pyr(1+prod(pind(1,:)):size(pyr,1)), ... pind(2:size(pind,1),:), ... lofilt, bfilts, edges, levs, bands); end res = upConv(res1, lo0filt, edges); %% residual highpass subband if any(levs == 0) res = upConv( subMtx(pyr, pind(1,:)), hi0filt, edges, [1 1], [1 1], size(res), res); end
github
phresher/MATLAB_Notes-master
ExtraSafePrimes.m
.m
MATLAB_Notes-master/exercises/Cody/ExtraSafePrimes.m
896
utf_8
d32b789b4f5d2865d2c620d0ae30d2ae
% https://cn.mathworks.com/matlabcentral/cody/problems/44385-extra-safe-primes % Did you know that the number 5 is the first safe prime? A safe prime is % a prime number that can be expressed as 2p+1, where p is also a prime. % To celebrate Cody's Five-Year Anniversary, write a function to determine % if a positive integer n is a safe prime in which the prime p % (such that n=2p+1) is also a safe prime. %% x = 0; assert(isequal(isextrasafe(x),false)) %% x = 5; assert(isequal(isextrasafe(x),false)) %% function tf = isextrasafe(x) if ~isprime(x) tf = false; return end [p, tf] = issafe(x); if ~tf return end [~, tf] = issafe(p); end function [p, tf] = issafe(x) tf = false; pSet = primes(x); for p = pSet if 2*p+1 == x tf = true; return end end end
github
phresher/MATLAB_Notes-master
RecamanSequenceII.m
.m
MATLAB_Notes-master/exercises/Cody/RecamanSequenceII.m
611
utf_8
1ed66c596c6214396ba8f7547ea0f04b
%% https://cn.mathworks.com/matlabcentral/cody/problems/44339-recaman-sequence-ii %% x = 0; y_correct = 2; assert(isequal(RecamanII(x),y_correct)) %% x = 90; y_correct = 35; assert(isequal(RecamanII(x),y_correct)) %% x = 123456789; y_correct = 46633; assert(isequal(RecamanII(x),y_correct)) %% function y = RecamanII(startPoint) n = 1; hist(1) = startPoint; while true n = n + 1; B=hist(n-1)-(n-1); C=0.^( abs(B+1) + (B+1) ); D=ismember(B, hist(1:n-1)); hist(n)=hist(n-1)+ (n-1) * (-1)^(C + D -1); if hist(n) == 1 y = n; return end end end
github
phresher/MATLAB_Notes-master
IsReal5.m
.m
MATLAB_Notes-master/exercises/Cody/IsReal5.m
774
utf_8
1705021c5e95d7d3e2c9e48dd2e2590d
%% n = 5; assert(isequal(is_it_really_a_5(n),1)) %% n = 15; assert(isequal(is_it_really_a_5(n),0)) %% function tf = is_it_really_a_5(n) tf = 0; n = num2str(n); lengthN = length(n); bit = mod(lengthN,3); group = fix(lengthN/3); switch bit case 1 if n(1) == '5' tf = 1; return end case 2 if n(1) ~= '1' && n(2) == '5' tf = 1; return end case 0 if (n(1) == '5') || (n(2) ~= '1' && n(3) == '5') tf = 1; return end end if group > 0 for i=1:group if (n(bit-2+3*group) == '5') || (n(bit-1+3*group) ~= '1' && n(bit+3*group) == '5') tf = 1; return end end end end
github
phresher/MATLAB_Notes-master
TheGlassHalfFull.m
.m
MATLAB_Notes-master/exercises/Cody/TheGlassHalfFull.m
1,299
utf_8
6f9c6adf0c03b42b52ea8829bb667c75
% https://cn.mathworks.com/matlabcentral/cody/problems/44307-the-glass-half-full % Identical glasses are placed in a triangular tower structure, such that the top level (L = 1) comprises one glass, the next level down (L = 2) comprises three glasses, the next level down (L = 3) comprises six glasses, and so on. % Follow the link to see a diagram shows the first three levels. The glasses in each levels are represented by the blue circles, while the yellow circles represent the positions of the glasses in the next higher level. % % Water is poured into the top glass at a constant volumetric flow rate. When the glass is filled, the water starts spilling over and into the glasses below. Note that water only spills outward , meaning that at some point, some glasses will remain empty. % v, the volume of a glass in liters % u, the volumetric flow rate in liters per second % L, a level in the glass structure % g, the number of glasses in that level % f, the number of glasses in that level that will be filled with water % t, the time, in seconds %% %% [g, f, t] = filltime(0.25, 0.1, 2); assert(isequal([g f t],[3 3 10])); %% function [g, f, t] = filltime(v, u, L) n = L; g = (1+n)*n/2; f = 3*n-3; t = (1+1.5*n*(n-1))*v/u; disp([g, f, t]); end
github
phresher/MATLAB_Notes-master
PerniciousAnniversaryProblem.m
.m
MATLAB_Notes-master/exercises/Cody/PerniciousAnniversaryProblem.m
527
utf_8
5f09facb34d0a82ae2227d96a6a0f6a9
% https://cn.mathworks.com/matlabcentral/cody/problems/2736 % Since Cody is 5 years old, it's pernicious. A Pernicious number is an % integer whose population count is a prime. Check if the given number is pernicious. %% x = 5; y_correct = true; assert(isequal(isPernicious(x),y_correct)) %% x = 17; y_correct = true; assert(isequal(isPernicious(x),y_correct)) %% function y = isPernicious(x) bin = dec2bin(x); bin(bin=='1')=1; bin(bin=='0')=0; binSum = sum(bin); y = isprime(binSum); end
github
phresher/MATLAB_Notes-master
AsciiBirthdayCake.m
.m
MATLAB_Notes-master/exercises/Cody/AsciiBirthdayCake.m
1,628
utf_8
ac0c52660ae1d91290b837348175b6fa
% https://cn.mathworks.com/matlabcentral/cody/problems/44380-ascii-birthday-cake % Given an age and a name, give draw an ASCII birthday cake. For example, % given the name "CODY" and the age 5, return a string with the following (no trailing spaces) % % 6 6 6 6 6 % | | | | | % __|_|_|_|_|__ % { } % { } % { CODY } % { } % {_____________} % This uses the string datatype, not a char array. %% cake = string(char([32 32 32 54 32 54 32 54 32 54 32 54 10 32 32 32 124 ... 32 124 32 124 32 124 32 124 10 32 95 95 124 95 124 95 124 95 124 95 ... 124 95 95 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 ... 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 67 79 ... 68 89 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 ... 32 125 10 123 95 95 95 95 95 95 95 95 95 95 95 95 95 125 10])); fprintf('%s\n', cake); assert(isequal(birthday_cake("CODY", 5), cake)); %% function s = birthday_cake(name, n) name = char(name); width = 2*n+5; nameWidth = length(name); s1 = blanks(width-3); s2 = blanks(width-3); s3 = blanks(width-1); s4 = blanks(width); s4(1) = '{'; s4(end) = '}'; s5 = s4; s6 = s5; s6(fix(width/2-nameWidth/2)+1:fix(width/2-nameWidth/2)+nameWidth) = name; s7 = s5; s8 = s7; s8(s8==' ') = '_'; for i=1:n s1(2+2*i)='6'; s2(2+2*i)='|'; s3(2+2*i)='|'; end s3(s3==' ') = '_'; s3(1) = ' '; s = [s1, 10, ... s2, 10, ... s3, 10, ... s4, 10, ... s5, 10, ... s6, 10, ... s7, 10, ... s8, 10]; fprintf('%s\n', s); s = string(s); end
github
phresher/MATLAB_Notes-master
MissingFive.m
.m
MATLAB_Notes-master/exercises/Cody/MissingFive.m
371
utf_8
a954322b0ec7d307deebf3e5adad0fd5
assert(isequal(regexprep(char(string(dec2missing5(3))),'^0*',''),'3')) assert(isequal(regexprep(char(string(dec2missing5(9541))),'^0*',''),'14081')) function y = dec2missing5(x) y = []; while true remainder = rem(x, 9); remainder(remainder>=5)=remainder+1; y = [num2str(remainder) y]; x = fix(x/9); if x == 0 break end end end
github
phresher/MATLAB_Notes-master
PentagonalNumbers.m
.m
MATLAB_Notes-master/exercises/Cody/PentagonalNumbers.m
951
utf_8
c46e8cf02090c73476fa7593e2b2fa58
% https://cn.mathworks.com/matlabcentral/cody/problems/44360-pentagonal-numbers % Your function will receive a lower and upper bound. % It should return all pentagonal numbers within that % inclusive range in ascending order. Additionally, % it should return an array that indicates those numbers % that are divisible by 5. For example, % % [p,d] = pentagonal_numbers(10,40) % should return % % p = [12,22,35] % d = [ 0, 0, 1] %% x1 = 1; x2 = 25; [p,d] = pentagonal_numbers(x1,x2); assert(isequal(p,[1,5,12,22])) assert(isequal(d,[0,1,0,0])) %% function [p,d] = pentagonal_numbers(lowerBound,upperBound) p = []; for i = lowerBound:upperBound num = double(i); flag1 = (sqrt(24*num+1) - fix(sqrt(24*num+1))) == 0; if ~flag1 continue; end flag2 = mod(sqrt(24*num+1)+1,6) == 0; if ~flag2 continue; end p = [p, int32(num)]; end d = mod(p, 5); d = logical(d); d = ~d; end
github
phresher/MATLAB_Notes-master
FivePrimeNumbers.m
.m
MATLAB_Notes-master/exercises/Cody/FivePrimeNumbers.m
850
utf_8
9b3593f73de2b951dc4aa1b653585400
% https://cn.mathworks.com/matlabcentral/cody/problems/44305-5-prime-numbers % Your function will be given lower and upper integer bounds. Your task is % to return a vector containing the first five prime numbers in that range % that contain the number five. But, if you can't find at least five such % numbers, the function should give up and return -1. %% n_min = 60; n_max = 1000; y_correct = [151,157,251,257,353]; assert(isequal(five_primes(n_min,n_max),y_correct)) %% function y = five_primes(n_min,n_max) p = primes(n_max); p = p(p>=n_min); y = nan(1,5); yNum = 1; for i=1:length(p) pStr = num2str(p(i)); flag = pStr(pStr == '5'); if isempty(flag) continue else y(yNum) = p(i); if yNum == 5 return end yNum = yNum + 1; end end y = -1; end
github
phresher/MATLAB_Notes-master
cubicAndSquare.m
.m
MATLAB_Notes-master/exercises/Cody/cubicAndSquare.m
619
utf_8
6fb23d0b54a90be335f4191bf7617aec
c = 5; y_correct = [2 11; 5 10]; y = sumoftwosquares(c); assert(isequal(y,y_correct)) function y = sumoftwosquares(c) cubic = c^3; y = []; first = 0; while true first = first + 1; second = 0; while true second = second + 1; squareSum = first^2 + second^2; if abs(squareSum - cubic) < 0.1 y = [y;first second]; break; elseif squareSum > cubic break end end if first > second break end end disp(y); end
github
phresher/MATLAB_Notes-master
EnergyOfAPhoton.m
.m
MATLAB_Notes-master/exercises/Cody/EnergyOfAPhoton.m
576
utf_8
6bfbcb1464e56d52379ed3c894f825b5
% https://cn.mathworks.com/matlabcentral/cody/problems/361-energy-of-a-photon % ? ? ? ? ? ? ? % % Given the frequency F of a photon in giga hertz. % % Find energy E of this photon in giga electron volts. % % Assume h, Planck's constant is about 4 femto electron-volt-second. % % To maximize benefits, it may help not looking at the Test Suite before trying any solution! % % For more info: https://en.wikipedia.org/wiki/Planck_constant %% F = 1; E_correct = 3/10^15; assert(photon_energy(F)>E_correct) %% function E = photon_energy(F) E=100/F; end
github
phresher/MATLAB_Notes-master
IsWin.m
.m
MATLAB_Notes-master/exercises/Cody/IsWin.m
561
utf_8
b8fd6230e078941ae006656b0c966586
%% x = [1 1 1 0 0 0 0 0 0]; y_correct = 1; assert(isequal(your_fcn_name(x),y_correct)) %% function flagWin = your_fcn_name(M) flagWin = false; sum1 = abs(sum(M,1)); sum1 = sum1(sum1==3); if ~isempty(sum1) flagWin = true; return end sum2 = abs(sum(M,2)); sum2 = sum2(sum2==3); if ~isempty(sum2) flagWin = true; return end sum3 = abs([M(1,1)+M(2,2)+M(3,3) ... M(1,3)+M(2,2)+M(3,1)]); sum3 = sum3(sum3==3); if ~isempty(sum3) flagWin = true; return end end
github
phresher/MATLAB_Notes-master
mySort.m
.m
MATLAB_Notes-master/1_2/homework/sort/mySort.m
1,918
utf_8
48df6a98d6971c4b3dd4d3abda1c14d7
function A = mySort(A, algorithm) % Practice several sort algorithms in one function. L=length(A); switch algorithm % insert sort case 'insert' for i=2:L for j=i:-1:2 if A(j)<A(j-1) [A(j), A(j-1)] = swap(A(j), A(j-1)); else break end end end % selection sort case 'selection' for i=1:L for j=i+1:L if A(i) > A(j) [A(i), A(j)] = swap(A(i), A(j)); end end end % heap sort case 'heap' % Build max-heap from x A = buildmaxheap(A,L); % Heapsort heapsize = L; for i = L:-1:2 % Put (n + 1 - i)th largest element in place [A(1), A(i)] = swap(A(1), A(i)); % Max-heapify x(1:heapsize) heapsize = heapsize - 1; A = maxheapify(A,1,heapsize); end end end function A = buildmaxheap(A,L) % Build max-heap out of x % Note: In practice, x xhould be passed by reference for i = floor(L / 2):-1:1 % Put children of x(i) in max-heap order A = maxheapify(A,i,L); end end function A = maxheapify(A,i,heapsize) % Put children of x(i) in max-heap order % Note: In practice, x xhould be passed by reference % Compute left/right children indices ll = 2 * i; % Note: In practice, use left bit shift rr = ll + 1; % Note: In practice, use left bit shift, then add 1 to LSB % Max-heapify if ((ll <= heapsize) && (A(ll) > A(i))) largest = ll; else largest = i; end if ((rr <= heapsize) && (A(rr) > A(largest))) largest = rr; end if (largest ~= i) [A(i), A(largest)] = swap(A(i), A(largest)); A = maxheapify(A,largest,heapsize); end end
github
Roboy/roboy_darkroom-master
multi_lighthouse_pose_estimator.m
.m
roboy_darkroom-master/darkroom/scripts/multi_lighthouse_pose_estimator.m
3,296
utf_8
e416582690c4abd06209336b785baa5e
%% load the data and parse into per sensor per lighthouse clear M = csvread('record_simulated_lighthouse0_calibration.log',1); [sensor_entries,asort] = sort(M(:,2)); b = M(asort,2:end); s = unique(sensor_entries); global sensors sensors = cell(2,length(s)); for i=1:length(s) temp = b(sensor_entries==i-1,:); [~,lighthouse_sort] = sort(temp(:,2)); temp = temp(lighthouse_sort,:); sensors{1,i} = temp(temp(:,2)==0,3:end); sensors{2,i} = temp(temp(:,2)==1,3:end); end %% read the relative sensor locations from yaml config = ReadYaml('calibration.yaml'); global rel_pos rel_pos = cell2mat(config.sensor_relative_locations(:,2:end)); %% pose estimation global sample sample = 2 true_pose = sensors{1,sample*2}(1,5:end); true_pose = [true_pose(1:4);true_pose(5:8);true_pose(9:12)]; % for sensor=1:length(rel_pos) % if(sensors{1,sensor}(sample,1)==0) % azimuth = sensors{1,sensor}(sample,3); % elevation = sensors{1,sensor}(sample+1,3); % else % azimuth = sensors{1,sensor}(sample+1,3); % elevation = sensors{1,sensor}(sample,3); % end % disp(sensor-1) % disp(elevation) % disp(azimuth) % end global lighthouse_pose lighthouse_pose = eye(4); % this is lighthouse to world pose lighthouse_pose(2,4) = 1 fun = @poseMultiLighthouse; x0 = [0,0,0,0,0,0]; options = optimset('Display','off'); x = fsolve(fun,x0,options); RT = createRTfrom(x); assert(norm(RT-true_pose)<0.0001) true_pose RT function RT = createRTfrom(x) alpha_squared = (x(1)^2 + x(2)^2 + x(3)^2)^2; q = [(1-alpha_squared)/(alpha_squared+1), 2*x(1)/(alpha_squared+1), 2*x(2)/(alpha_squared+1), 2*x(3)/(alpha_squared+1)]; q = q/norm(q); qw = q(1); qx = q(2); qy = q(3); qz = q(4); tx = 2*qx; ty = 2*qy; tz = 2*qz; twx = tx*qw; twy = ty*qw; twz = tz*qw; txx = tx*qx; txy = ty*qx; txz = tz*qx; tyy = ty*qy; tyz = tz*qy; tzz = tz*qz; RT = [1-(tyy+tzz), txy-twz, txz+twy, x(4); txy+twz, 1-(txx+tzz), tyz-twx, x(5); txz-twy, tyz+twx , 1-(txx+tyy), x(6)]; end function F = poseMultiLighthouse(x) global rel_pos global sensors global lighthouse_pose global sample RT = createRTfrom(x); rt = [RT(1,1), RT(2,1), RT(3,1), RT(1,2), RT(2,2), RT(3,2), RT(1,3), RT(2,3), RT(3,3), RT(1,4), RT(2,4), RT(3,4)]; CD = zeros(2*length(rel_pos),12); b = zeros(2*length(rel_pos),1); for sensor=1:length(rel_pos) if(sensors{1,sensor}(sample,1)==0) azimuth = sensors{1,sensor}(sample,3); elevation = sensors{1,sensor}(sample+1,3); else azimuth = sensors{1,sensor}(sample+1,3); elevation = sensors{1,sensor}(sample,3); end u = tan(pi/2 - azimuth); v = tan(elevation - pi/2); C = lighthouse_pose(2,:)*u-lighthouse_pose(1,:); D = lighthouse_pose(2,:)*v-lighthouse_pose(3,:); X = rel_pos(sensor,1); Y = rel_pos(sensor,2); Z = rel_pos(sensor,3); CD(sensor*2:sensor*2+1,:) = [C(1)*X C(2)*X C(3)*X C(1)*Y C(2)*Y C(3)*Y C(1)*Z C(2)*Z C(3)*Z C(1) C(2) C(3); D(1)*X D(2)*X D(3)*X D(1)*Y D(2)*Y D(3)*Y D(1)*Z D(2)*Z D(3)*Z D(1) D(2) D(3)]; b(sensor*2:sensor*2+1) = [-C(4); -D(4)]; end F = CD*rt' - b; end
github
Roboy/roboy_darkroom-master
mergeimports.m
.m
roboy_darkroom-master/darkroom/scripts/YAMLREADER/mergeimports.m
5,334
utf_8
2564bb2fc532430c64ab664d1cfceb4c
%========================================================================== % Walks through a tree structure data. Whenever it finds a structure, which % have field named 'import' it assumes that in that field is a cell array % and merges all structures found in that array. Parameter verb is used for % debugging purposes. %========================================================================== function result = mergeimports(data, verb) if ~exist('verb','var') verb = 0; end; result = recurse(data, 0, [], verb); end %-------------------------------------------------------------------------- % Recursion dispatcher, calls appropriate method for cell/structure or % displays data if the parameter data is not of mentioned type. % addit ... for possible future use, now unused % verb ... for debugging % function result = recurse(data, level, addit, verb) indent = repmat(' | ',1,level); % for debugging if iscell(data) result = iter_cell(data, level, addit, verb); elseif isstruct(data) result = iter_struct(data, level, addit, verb); else if any(verb == 1) % for debugging fprintf([indent,'Some data: ']); disp(data); end; result = data; end; end %-------------------------------------------------------------------------- % Walks through a cell array and calls recurse on every field. % data ... Assumed to be a cell. Data to be walked. % level ... Level in the tree, root has zero. % addit, verb ... for debugging % function result = iter_cell(data, level, addit, verb) indent = repmat(' | ',1,level); % for debugging result = {}; if any(verb == 1); fprintf([indent,'cell {\n']); end; % for debugging for i = 1:length(data) itemcontent = recurse(data{i}, level + 1, addit, verb); result{end + 1} = itemcontent; end; if any(verb == 1); fprintf([indent,'} cell\n']); end; % for debugging end %-------------------------------------------------------------------------- % Walks through a struct and calls recurse on every field. If there is a % field called 'import' it calls process_import_field on its content. Then % merges processed import with the rest of the structure. Meaning of all % parameters is similar to those of iter_cell. % function result = iter_struct(data, level, addit, verb) indent = repmat(' | ',1,level); % for debugging result = struct(); collected_imports = {}; if any(verb == 1); fprintf([indent,'struct {\n']); end; % for debugging for i = fields(data)' fld = char(i); if any(verb == 1); fprintf([indent,' +-field ',fld,':\n']); end; % for debugging result.(fld) = recurse(data.(fld), level + 1, addit, verb); % Tree back-pass - all potential underlying imports were processed, % so process import here, if needed. if isequal(fld, 'import') processed_import = process_import_field(result.(fld)); result = rmfield(result, 'import'); if isstruct(processed_import) collected_imports{end+1} = processed_import; % It is maybe useless to collect imports to the array since % there can be only one field named 'import' per structure. % collected_imports is proposed to be changed to a simple % variable. else % One of imports was not a struct. In following versions it % probably won't be an error and will merge to a cell with % structs. disp(processed_import); error('Expected struct, otherwise it cannot be merged with the rest.'); end; end; end; for i = 1:length(collected_imports) result = merge_struct(result, collected_imports{i}, {}, 'deep'); end; if any(verb == 1); fprintf([indent,'} struct\n']); end; % for debugging end %-------------------------------------------------------------------------- % Walks through the data parameter, which is assumed to be a cell. Merges % all structures in that cell and returns them as a struct or possibly as a % cell of merged struct and unmeregeable data. % function result = process_import_field(data) if iscell(data) merged_structs = struct(); collected_nonstruct = {}; for i = 1:length(data) if isstruct(data{i}) merged_structs = merge_struct(merged_structs, data{i}, {}, 'deep'); else collected_nonstruct{end+1} = data{i}; end; end; if isempty(collected_nonstruct) result = merged_structs; elseif isempty(merged_structs) result = collected_nonstruct; else result = {merged_structs; collected_nonstruct}; end; else % For clarity and simplicity, the whole transformation is done so % that every import field in a struct is cell array even there is % only one object to be imported. error('BUG: import field should always contain a cell.'); end; end %==========================================================================
github
Roboy/roboy_darkroom-master
ReadYamlRaw.m
.m
roboy_darkroom-master/darkroom/scripts/YAMLREADER/ReadYamlRaw.m
8,106
utf_8
e088fcbe02b123cafe72ee93107295fe
%========================================================================== % Reads YAML file, converts YAML sequences to MATLAB cell columns and YAML % mappings to MATLAB structs % % filename ... name of yaml file to be imported % verbose ... verbosity level (0 or absent = no messages, % 1 = notify imports) %========================================================================== function result = ReadYamlRaw(filename, verbose, nosuchfileaction, treatasdata) if ~exist('verbose','var') verbose = 0; end; if ~exist('nosuchfileaction','var') nosuchfileaction = 0; end; if ~ismember(nosuchfileaction,[0,1]) error('nosuchfileexception parameter must be 0,1 or missing.'); end; if(~exist('treatasdata','var')) treatasdata = 0; end; if ~ismember(treatasdata,[0,1]) error('treatasdata parameter must be 0,1 or missing.'); end; [pth,~,~] = fileparts(mfilename('fullpath')); try import('org.yaml.snakeyaml.*'); javaObject('Yaml'); catch dp = [pth filesep 'external' filesep 'snakeyaml-1.9.jar']; if not(ismember(dp, javaclasspath ('-dynamic'))) javaaddpath(dp); % javaaddpath clears global variables...!? end import('org.yaml.snakeyaml.*'); end; setverblevel(verbose); % import('org.yaml.snakeyaml.Yaml'); % import here does not affect import in load_yaml ...!? result = load_yaml(filename, nosuchfileaction, treatasdata); end %-------------------------------------------------------------------------- % Actually performs YAML load. % - If this is a first call during recursion it changes cwd to the path of % given filename and stores the old path. Then it calls the YAML parser % and runs the recursive transformation. After transformation or when an % error occurs, it sets cwd back to the stored value. % - Otherwise just calls the parser and runs the transformation. % function result = load_yaml(inputfilename, nosuchfileaction, treatasdata) persistent nsfe; if exist('nosuchfileaction','var') %isempty(nsfe) && nsfe = nosuchfileaction; end; persistent tadf; if isempty(tadf) && exist('treatasdata','var') tadf = treatasdata; end; yaml = org.yaml.snakeyaml.Yaml(); % It appears that Java objects cannot be persistent...!? if ~tadf [filepath, filename, fileext] = fileparts(inputfilename); if isempty(filepath) pathstore = cd(); else pathstore = cd(filepath); end; end; try if ~tadf result = scan(yaml.load(fileread([filename, fileext]))); else result = scan(yaml.load(inputfilename)); end; catch ex if ~tadf cd(pathstore); end; switch ex.identifier case 'MATLAB:fileread:cannotOpenFile' if nsfe == 1 error('MATLAB:MATYAML:FileNotFound', ['No such file to read: ',filename,fileext]); elseif nsfe == 0 warning('MATLAB:MATYAML:FileNotFound', ['No such file to read: ',filename,fileext]); result = struct(); return; end; end; rethrow(ex); end; if ~tadf cd(pathstore); end; end %-------------------------------------------------------------------------- % Determine node type and call appropriate conversion routine. % function result = scan(r) if isa(r, 'char') result = scan_string(r); elseif isa(r, 'double') result = scan_numeric(r); elseif isa(r, 'logical') result = scan_logical(r); elseif isa(r, 'java.util.Date') result = scan_datetime(r); elseif isa(r, 'java.util.List') result = scan_list(r); elseif isa(r, 'java.util.Map') result = scan_map(r); else error(['Unknown data type: ' class(r)]); end; end %-------------------------------------------------------------------------- % Transforms Java String to MATLAB char % function result = scan_string(r) result = char(r); end %-------------------------------------------------------------------------- % Transforms Java double to MATLAB double % function result = scan_numeric(r) result = double(r); end %-------------------------------------------------------------------------- % Transforms Java boolean to MATLAB logical % function result = scan_logical(r) result = logical(r); end %-------------------------------------------------------------------------- % Transforms Java Date class to MATLAB DateTime class % function result = scan_datetime(r) result = DateTime(r); end %-------------------------------------------------------------------------- % Transforms Java List to MATLAB cell column running scan(...) recursively % for all ListS items. % function result = scan_list(r) result = cell(r.size(),1); it = r.iterator(); ii = 1; while it.hasNext() i = it.next(); result{ii} = scan(i); ii = ii + 1; end; end %-------------------------------------------------------------------------- % Transforms Java Map to MATLAB struct running scan(...) recursively for % content of every Map field. % When there is field, which is recognized to be the >import keyword<, an % attempt is made to import file given by the field content. % % The result of import is so far stored as a content of the item named 'import'. % function result = scan_map(r) it = r.keySet().iterator(); while it.hasNext() next = it.next(); i = next; ich = char(i); if iskw_import(ich) result.(ich) = perform_import(r.get(java.lang.String(ich))); else result.(genvarname(ich)) = scan(r.get(java.lang.String(ich))); end; end; if not(exist('result','var')) result={}; end end %-------------------------------------------------------------------------- % Determines whether r contains a keyword denoting import. % function result = iskw_import(r) result = isequal(r, 'import'); end %-------------------------------------------------------------------------- % Transforms input hierarchy the usual way. If the result is char, then % tries to load file denoted by this char. If the result is cell then tries % to do just mentioned for each cellS item. % function result = perform_import(r) r = scan(r); if iscell(r) && all(cellfun(@ischar, r)) result = cellfun(@load_yaml, r, 'UniformOutput', 0); elseif ischar(r) result = {load_yaml(r)}; else disp(r); error(['Importer does not unterstand given filename. '... 'Invalid node displayed above.']); end; end %-------------------------------------------------------------------------- % Sets verbosity level for all load_yaml infos. % function setverblevel(level) global verbose_readyaml; verbose_readyaml = 0; if exist('level','var') verbose_readyaml = level; end; end %-------------------------------------------------------------------------- % Returns current verbosity level. % function result = getverblevel() global verbose_readyaml; result = verbose_readyaml; end %-------------------------------------------------------------------------- % For debugging purposes. Displays a message as level is more than or equal % the current verbosity level. % function info(level, text, value_to_display) if getverblevel() >= level fprintf(text); if exist('value_to_display','var') disp(value_to_display); else fprintf('\n'); end; end; end %==========================================================================
github
Roboy/roboy_darkroom-master
makematrices.m
.m
roboy_darkroom-master/darkroom/scripts/YAMLREADER/makematrices.m
5,810
utf_8
afb188bbb6dfad249186bc0158a07fa1
%========================================================================== % Recursively walks through a Matlab hierarchy and substitutes cell vectors % by a matrix when possible. % Specifically substitutes cell objects like % % {{1,2,3},{4,5,6}} % % by % % {1,2,3;4,5,6} % % It leaves other objects unchanged except that it may change cell % orientations (from column to row, etc.) % % Parameter makeords determines whether to convert from cells to normal % matrices whenever possible (1) or leave matrices as cells (0). %========================================================================== function result = makematrices(r, makeords) result = recurse(r, 0, [], makeords); end %-------------------------------------------------------------------------- % % function result = recurse(data, level, addit, makeords) if iscell(data) result = iter_cell(data, level, addit, makeords); elseif isstruct(data) result = iter_struct(data, level, addit, makeords); else result = scan_data(data, level, addit); end; end %-------------------------------------------------------------------------- % Iterates through cell array data. A cell array here is treated as a % simple sequence, hence it is processed regardless its shape. The array is % transformed to a cell matrix if it satisfies following conditions: % - It is vector % - All its items are cells % - All its items are vectors % - All its items are alligned (are of the same size) % - All its items are rows of a matrix (see ismatrixrow(...)) % Otherwise the content is left unchanged. % function result = iter_cell(data, level, addit, makeords) if isvector(data) && ... iscell_all(data) && ... isvector_all(data) && ... isaligned_all(data) && ... ismatrixrow_all(data) tmp = data; tmp = cellfun(@cell2mat, tmp, 'UniformOutput', 0); tmp = cellfun(@torow, tmp, 'UniformOutput', 0); tmp = tocolumn(tmp); tmp = cell2mat(tmp); if ~makeords tmp = num2cell(tmp); end; result = tmp; elseif isempty(data) result = []; else result = {}; for i = 1:length(data) result{i} = recurse(data{i}, level + 1, addit, makeords); end; end; end %-------------------------------------------------------------------------- % % function result = iter_struct(data, level, addit, makeords) result = struct(); for i = fields(data)' fld = char(i); result.(fld) = recurse(data.(fld), level + 1, addit, makeords); end; end %-------------------------------------------------------------------------- % % function result = scan_data(data, level, addit) result = data; end %-------------------------------------------------------------------------- % % function result = iscell_all(cellvec) result = all(cellfun(@iscell, cellvec)); end %-------------------------------------------------------------------------- % Determines whether all items of cellvec are of the same length. % function result = isaligned_all(cellvec) siz = numel(cellvec{1}); result = all(cellfun(@numel, cellvec) == siz); end %-------------------------------------------------------------------------- % % function result = ismatrixrow_all(cellvec) result = all(cellfun(@ismatrixrow, cellvec)); end %-------------------------------------------------------------------------- % Determines whether cellvec can constitute a matrix row. The vector is a % matrix row candidate if: % - all of its items are numeric % - all of its items are single (neither vectors nor matrices etc.) % - all of its items are compatible for concatenation to an ordinary % vector (this is maybe automatically reached by isnumeric_all) % function result = ismatrixrow(cellvec) result = ... (isnumeric_all(cellvec) || islogical_all(cellvec) || isstruct_all(cellvec)) && ... issingle_all(cellvec) && ... iscompatible_all(cellvec); end %-------------------------------------------------------------------------- % % function result = isnumeric_all(cellvec) result = all(cellfun(@isnumeric, cellvec)); end %-------------------------------------------------------------------------- % % function result = islogical_all(cellvec) result = all(cellfun(@islogical, cellvec)); end %-------------------------------------------------------------------------- % % function result = issingle_all(cellvec) result = all(cellfun(@issingle, cellvec)); end %-------------------------------------------------------------------------- % % function result = iscompatible_all(cellvec) result = true; for i = 1:(length(cellvec) - 1) result = result && iscompatible(cellvec{i}, cellvec{i + 1}); end end %-------------------------------------------------------------------------- % % function result = iscompatible(obj1, obj2) result = isequal(class(obj1), class(obj2)); end %-------------------------------------------------------------------------- % % function result = isvector_all(cellvec) result = all(cellfun(@isvector, cellvec)); end %-------------------------------------------------------------------------- % % function result = isstruct_all(cellvec) result = all(cellfun(@isstruct, cellvec)); end %-------------------------------------------------------------------------- % % function result = torow(vec) result = tocolumn(vec).'; end %-------------------------------------------------------------------------- % % function result = tocolumn(vec) result = vec(:); end
github
Roboy/roboy_darkroom-master
deflateimports.m
.m
roboy_darkroom-master/darkroom/scripts/YAMLREADER/deflateimports.m
1,847
utf_8
44bea4918316676d13e94582fc62ed7b
%========================================================================== % Transforms structures: % - import: A, B % - import: C % - import: D, E, F % % into: % - import: A, B, C, D, F, F % %========================================================================== function result = deflateimports(r) result = recurse(r, 0, []); end function result = recurse(data, level, addit) if iscell(data) && ~ismymatrix(data) result = iter_cell(data, level, addit); elseif isstruct(data) result = iter_struct(data, level, addit); else %disp(data); result = data; end; end function result = iter_cell(data, level, addit) result = {}; icollect = {}; ii = 1; for i = 1:length(data) datai = data{i}; if issingleimport(datai) if ~iscell(datai.import) datai.import = {datai.import}; end; for j = 1:length(datai.import) icollect{end + 1} = datai.import{j}; end; else result{ii} = recurse(datai, level + 1, addit); ii = ii + 1; end; end; if ~isempty(icollect) result{end + 1} = struct('import',{icollect}); end; end function result = iter_struct(data, level, addit) result = struct(); for i = fields(data)' fld = char(i); result.(fld) = recurse(data.(fld), level + 1, addit); end; end function result = issingleimport_all(r) result = all(cellfun(@issingleimport, r)); end function result = issingleimport(r) result = isstruct(r) && length(fields(r)) == 1 && isfield(r, 'import'); end function result = addall(list1, list2) for i = 1:length(list2) list1{end + 1} = list2{i}; end; result = list1; end
github
Roboy/roboy_darkroom-master
dosubstitution.m
.m
roboy_darkroom-master/darkroom/scripts/YAMLREADER/dosubstitution.m
1,084
utf_8
4c5ec59493e7d2534379763e2d50520c
%========================================================================== %========================================================================== function result = dosubstitution(r, dictionary) if ~exist('dictionary','var') dictionary = {}; end; result = recurse(r, 0, dictionary); end function result = recurse(data, level, dictionary) if iscell(data) && ~ismymatrix(data) result = iter_cell(data, level, dictionary); elseif isstruct(data) result = iter_struct(data, level, dictionary); elseif ischar(data) && isfield(dictionary, data) result = dictionary.(data); else result = data; end; end function result = iter_cell(data, level, dictionary) result = {}; for i = 1:length(data) result{i} = recurse(data{i}, level + 1, dictionary); end; end function result = iter_struct(data, level, dictionary) result = data; for i = fields(data)' fld = char(i); result.(fld) = recurse(data.(fld), level + 1, dictionary); end; end
github
Roboy/roboy_darkroom-master
merge_struct.m
.m
roboy_darkroom-master/darkroom/scripts/YAMLREADER/merge_struct.m
1,366
utf_8
afc9cfb74c801763c1a771acc6be9aec
%-------------------------------------------------------------------------- % Does merge of two structures. The result is structure which is union of % fields of p and s. If there are equal field names in p and s, fields in p % are overwriten with their peers from s. % function result = merge_struct(p, s, donotmerge, deep) if ~( isstruct(p) && isstruct(s) ) error('Only structures can be merged.'); end; if ~exist('donotmerge','var') donotmerge = {}; end if ~exist('deep','var') deep = 0; elseif strcmp(deep, 'deep') deep = 1; end; result = p; for i = fields(s)' fld = char(i); if any(cellfun(@(x)isequal(x, fld), donotmerge)) continue; end; % if isfield(result, fld) % % Just give the user a hint that there may be some information % % lost. % fprintf(['Overwriting field ',fld,'\n']); % end; %disp('Assigning:') %disp(['fieldname: ',fld]); %disp(s.(fld)); %disp('----------'); if deep == 1 && isfield(result, fld) && isstruct(result.(fld)) && isstruct(s.(fld)) result.(fld) = merge_struct(result.(fld), s.(fld), donotmerge, deep); else result.(fld) = s.(fld); end; end; end