text:
function bool = is_dim_singleton(varargin)
%IS_DIM_SINGLETON true for a singleton axis dimension
%
%   Usage: bool = is_dim_singleton(x1,x2,...)
%
%   Input parameters:
%       x1,x2,... - axis / m; single value or [xmin,xmax] or nD-array
%
%   Output parameters:
%       bool      - array of logical indicating whether each input is a
%                   singleton dimension
%
%   See also: is_dim_custom, xyz_axes_selection, plot_sound_field

%*****************************************************************************
% The MIT License (MIT)                                                      *
%                                                                            *
% Copyright (c) 2010-2019 SFS Toolbox Developers                             *
%                                                                            *
% Permission is hereby granted,  free of charge,  to any person  obtaining a *
% copy of this software and associated documentation files (the "Software"), *
% to deal in the Software without  restriction, including without limitation *
% the rights  to use, copy, modify, merge,  publish, distribute, sublicense, *
% and/or  sell copies of  the Software,  and to permit  persons to whom  the *
% Software is furnished to do so, subject to the following conditions:       *
%                                                                            *
% The above copyright notice and this permission notice shall be included in *
% all copies or substantial portions of the Software.                        *
%                                                                            *
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
% IMPLIED, INCLUDING BUT  NOT LIMITED TO THE  WARRANTIES OF MERCHANTABILITY, *
% FITNESS  FOR A PARTICULAR  PURPOSE AND  NONINFRINGEMENT. IN NO EVENT SHALL *
% THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
% LIABILITY, WHETHER  IN AN  ACTION OF CONTRACT, TORT  OR OTHERWISE, ARISING *
% FROM,  OUT OF  OR IN  CONNECTION  WITH THE  SOFTWARE OR  THE USE  OR OTHER *
% DEALINGS IN THE SOFTWARE.                                                  *
%                                                                            *
% The SFS Toolbox  allows to simulate and  investigate sound field synthesis *
% methods like wave field synthesis or higher order ambisonics.              *
%                                                                            *
% https://sfs.readthedocs.io                            sfstoolbox@gmail.com *
%*****************************************************************************

%% ===== Checking input parameters =======================================
isargnumeric(varargin{:});

%% ===== Computation =====================================================
bool = cellfun(@(x) numel(x) <= 2 && x(1) == x(end), varargin);

author: sfstoolbox

repo: sfs-matlab


text:
function [s_map1 s_map2 s3] = s3_map(img, show_res)
% Input: img is a gray scale image, in double type, range from 0 - 255.
% You have to convert to gray scale if your image
% is color. You also have to cast img to double in order to run this code
% Parameter show_res = 1 to show results
% Output:
% s_map1: The sharpness map measure based on spectral slope
% s_map2: The sharpness map measure based on total variation (spatial)
% s3: the final sharpness map (combination of s_map1 and s_map2)
if nargin < 2
  show_res = 0;
end

% ----------------------------------------------------------------------
% blr_map1
s_map1 = spectral_map(img, 16);

%-----------------------------------------------------------------------
% blr_map2
s_map21 = spatial_map(img, 8); % Spatial map, blocks start from (1,1)
s_map22 = spatial_map(img, 4); % Spatial map, blocks start from (5,5)
s_map2 = max(s_map21, s_map22);

%-----------------------------------------------------------------------
% combine
s_map1(s_map1 < -99) = 0;
s_map2(s_map2 < -99) = 0;

alpha = 0.5;
s3 = (s_map1.^alpha) .* ((s_map2).^(1-alpha));
if show_res
  figure; imshow(s_map1);
  figure; imshow(s_map2);
  figure; imshow(img/255);
  figure; imshow(s3);
end
end %function

%% Spectral Sharpness, slope of power spectrum
function res = spectral_map(img, pad_len)
blk_size = 32; %big block size for more coefficients of the power spectrum
d_blk = blk_size/4; % Distance b/w blocks

pad_L = fliplr(img(:, 1:pad_len)); % Take 16 columns on the left of the
                                    % original image to pad to the left
pad_R = fliplr(img(:, end-pad_len:end));%Take 16 columns on the right of the
                                        % original image to pad to the
                                        % right
img = [pad_L img pad_R]; %Pad left and right

pad_T = flipud(img(1:pad_len, :)); %Similarly, pad top and bottom
pad_B = flipud(img(end-pad_len:end, :));
img = [pad_T; img; pad_B];

num_rows = size(img, 1);
num_cols = size(img, 2);
res = zeros(num_rows, num_cols) - 100;
contrast_thresold = 0;

%disp_progress; % Just to show progress
for r = blk_size/2+1:d_blk:num_rows-blk_size/2 % Just start from inside blocks
                                                % of the padded image
  %disp_progress(r, num_rows);
  for c = blk_size/2+1:d_blk:num_cols-blk_size/2
    gry_blk = img(...
      r-blk_size/2:r+blk_size/2-1,...
      c-blk_size/2:c+blk_size/2-1 ...
      );
    contrastMap = contrast_map_overlap(gry_blk);
    if(max(contrastMap(:))> contrast_thresold) % Avoid the case when contrast = 0
      val = blk_amp_spec_slope_eo_toy_1(gry_blk); % Val(1) will be the slope of
                                                % power spectrum of the block
      val(1) = 1 - 1 ./ (1 + exp(-3*(val(1) - 2))); %Input to a sigmoid function
      %if(max(gry_blk(:))==min(gry_blk(:))) % Black block
       % val_1 = 0;
      %else
        val_1 = val(1);
      %end
    else
        val_1 = 0;
    end
    res(...
      r-d_blk/2:r+d_blk/2-1,...
      c-d_blk/2:c+d_blk/2-1 ...
      ) = val_1;
  end
end
% Remove padded parts
res = res(pad_len+1:end-pad_len-1, pad_len+1:end-pad_len-1);
end % function

%% ---Spatial Sharpness, local total variation
function res = spatial_map(img, pad_len)
% pad_len = 8 if we dont want to shift img
% pad_len = 4 if we want to shift img by 4;
blk_size = 8;

pad_L = fliplr(img(:, 1:pad_len)); % Take pad_len columns on the left of
                                   % the original image to pad to the left
pad_R = fliplr(img(:, end-pad_len:end));%Take pad_len columns on the right
                                % of the original image to pad to the right
img = [pad_L img pad_R]; %Pad left and right

pad_T = flipud(img(1:pad_len, :)); %Similarly, pad top and bottom
pad_B = flipud(img(end-pad_len:end, :));
img = [pad_T; img; pad_B];

[num_rows, num_cols] = size(img);
res = zeros(num_rows, num_cols);

for r = blk_size/2+1 : blk_size : num_rows-blk_size/2
  for c = blk_size/2+1 : blk_size : num_cols-blk_size/2
    gry_blk = img(...
      r-blk_size/2 : r+blk_size/2-1,...
      c-blk_size/2 : c+blk_size/2-1 ...
      );
    % Measure local total variation for every 2x2 block of gry_blk
    tmp_idx = 1;
    for i = 1 : blk_size - 1
      for j = 1 : blk_size - 1
        tv_tmp(tmp_idx) = (abs(gry_blk(i,j) - gry_blk(i,j+1))...
          + abs(gry_blk(i,j) - gry_blk(i+1,j))...
          + abs(gry_blk(i,j) - gry_blk(i+1,j+1))...
          + abs(gry_blk(i+1,j+1) - gry_blk(i+1,j))...
          + abs(gry_blk(i+1,j) - gry_blk(i,j+1))...
          + abs(gry_blk(i+1,j+1) - gry_blk(i,j+1)))/255; %Each pixel ranges
        %from 0 - 255, so divide by 255 to make it from 0 - 1
        tmp_idx = tmp_idx + 1;
      end
    end

    tv_max = max(tv_tmp) / 4; % Normalize tv_max to be from 0 -1. We can
                              % easily see that the maximum value of total
                              % variation for each 2x2 block is 4, in
                              % blocks like   1 0
                              %               0 1

    res(...
      r - blk_size/2 : r + blk_size/2-1,...
      c - blk_size/2 : c + blk_size/2-1 ...
      ) = tv_max;
  end
end
res = res(pad_len + 1 : end-pad_len - 1, pad_len + 1 : end-pad_len - 1);

end % function

author: zhangqianqianQQ

repo: MachineVisionAlgorithm


text:
function rx = rxMidCorRx(rx);
%
% rx = rxMidCorRx(rx);
%
% Add a mid-coronal Rx for aligning coronal inplanes
% to a volume anatomy using mrRx.
%
% ras 08/05.
if ieNotDefined('rx')
    cfig = findobj('Tag','rxControlFig');
    rx = get(cfig,'UserData');
end

% % store the existing settings
% rx = rxStore(rx,'Last Setting');

% I find these rotations / flips cover the most common case,
% where the first slice is the most anterior, pretty well;
% and allow the 'axial rotate' slider to do the intuitive thing,
% namely, a pitch rotation:
voxRatio = rx.rxVoxelSize ./ rx.volVoxelSize;
trans = rx.volDims/2 - (rx.rxDims/2 .* voxRatio);;
rot = deg2rad([-90 90 90]);
scale = [1 1 1];
newXform = affineBuild(trans, rot, scale, [0 0 0]);

% if there's an Rx Figure open, set it to axial view, which
% is easiest to prescribe off of:
if ishandle(rx.ui.volOri(1))
    selectButton(rx.ui.volOri, 1);
end

rx = rxSetXform(rx,newXform);
rx = rxStore(rx, 'Mid Coronal Rx');

return

author: vistalab

repo: vistasoft

save_path: github-repos/MATLAB/vistalab-vistasoft


text:
function [C, S] = QLiftDec2MaxMax(X, N)
%-----------------------------------------------------------------------------
% QLiftDec2MaxMax
% Multilevel 2-D decomposition by the lifting scheme and using quincunx grids
%
% The MaxMax scheme has been proposed by Heijmans and Goutsias, see e.g.
%    H.J.A.M. Heijmans, J. Goutsias,
%    Multiresolution signal decomposition schemes.
%    Part 2: morphological wavelets.
%    CWI Report PNA-R9905, Amsterdam, 1999.
%    http://repository.cwi.nl:8888/cwi_repository/docs/IV/04/04625D.pdf
%
% Calls for: QLmaxlev,
%            storeQ1001, storeR,
%            getcolor01, getcolor10, getcolor00, getcolor11,
%            putcolor01, putcolor10, putcolor00, putcolor11.
% See also: QLiftRec2MaxMin
%
% Design and implementation by:
% Dr. Paul M. de Zeeuw <Paul.de.Zeeuw@cwi.nl>  http://homepages.cwi.nl/~pauldz/
% Last Revision: February 6, 2003.
% (c) 1999-2002 Stichting CWI, Amsterdam
%-----------------------------------------------------------------------------
%Firstly, check input data
%
if  isempty(X)
  error(' QLiftDec2MaxMax - empty matrix ');
else
  if mod(N, 2) == 1
    error(' QLiftDec2MaxMax - only an even number of levels is accepted ');
  end
  if QLmaxlev(size(X), 'maxmax') < N
    error(' QLiftDec2MaxMax - too many levels requested ');
  end
  if N < 2
    disp([' QLiftDec2MaxMax - WARNING too few levels requested ' ...
          '-> empty decomposition ']);
  end
end
%
%Secondly, start decomposition
%
O = X; % For the sake of efficient use of memory this could be improved upon.
% We descend to coarser grids, integer lev indicates number of scale.
C = []; S = [];

for lev=1:2:N
%
   [nO, mO] = size(O);
   if ( nO < 3 ) || ( mO < 3)
     error(' QLiftDec2MaxMax - too many levels ');
   end
   minO = min(min(O));
   maxO = max(max(O));
   cmin = minO-(maxO-minO);
%  cmax = maxO+(maxO-minO);
%
%  The Lifting Scheme proceeds from a rectangular grid
%  towards a quincunx grid.
%
%  Stage: predict
   A00 =getcolor00(O);
   A11 =getcolor11(O);
%  Quincunx grid Q0011 is the union of the values at .00 and .11: "even slots"
%  Quincunx grid Q1001 is the union of the values at .10 and .01: "odd slots"
   Q1001D01 = getcolor01(O) - synA01max(A11, A00, cmin);                % Y1
   Q1001D10 = getcolor10(O) - synA10max(A11, A00, cmin);                % Y1
%  At this point the union (quincunx) of Q1001D01 & Q1001D10
%  contains the DETAILS of O.
%
%  For the inverse transform Q1001D01 and Q1001D10 have to be stored:
   [C, S] = storeQ1001( Q1001D10, Q1001D01, lev, 'd', C, S);
%
%  Stage: update
   Q0011A00 = A00 + ...
        max(zeros(size(A00)), synA00max(Q1001D10, Q1001D01, cmin));     % X1
   clear A00;
   Q0011A11 = A11 + ...
        max(zeros(size(A11)), synA11max(Q1001D10, Q1001D01, cmin));     % X1
   clear A11 Q1001D10 Q1001D01;
%  At this point the union (quincunx) of Q0011A00 & Q0011A11
%  contains the updated APPROXIMATION of O, the DETAILS of O
%  were in the union (quincunx) of Q1001D01 & Q1001D10 (see above).
%
%  The Lifting Scheme proceeds by a subsequent step from quincunx
%  to rectangular grid.
%
%  Q0011 is split into the 11 colour with the "odd slots" and
%  the 00 colour with the "even slots".
%
%  Stage: predict
   DETAIL11 = Q0011A11 - synA11Qmax(Q0011A00, size(Q0011A11), cmin);        % Y2
   clear Q0011A11;
%  Stage: update
   APPROX00 = Q0011A00 + ...
     max(zeros(size(Q0011A00)), synA00Qmax(DETAIL11, size(Q0011A00), cmin));% X2
%
%  DETAIL11 presents the detail gridfunction w.r.t. Q0011
%  APPROX00 now represents the updated version of the approximation of Q0011
%
%  For the inverse transform DETAIL11 has to be stored:
   [C, S] = storeR( DETAIL11, lev+1, 'd', C, S);
   clear Q0011A00 DETAIL11;
%
%  At this point gridfunction DETAIL11 containing the DETAILS has been stored,
%  gridfunction APPROX00 contains the updated APPROXIMATION, on the (down-
%  sampled) rectangular grid and has to be stored as well if at the highest
%  scale.
%  Note that APPROX00 is downsampled onto a rectangular grid with dimensions of
%  half size of the original O.
   if lev+1 >= N
     [C, S] = storeR(APPROX00, lev+1, 'a', C, S);
%    It is obligatory that at least at one scale the Approximation has to be
%    stored or else the scheme cannot be inverted.
     clear APPROX00;
%    In the Lifting Scheme all scales have now been processed!
   else
%    We proceed to the next scale.
     O = APPROX00; clear APPROX00;
   end
end
%-----------------------------------------------------------------------------

author: Sable

repo: mcbench-benchmarks


text:
% The null space of a 3DOF robot when considered redundant.
% if the task m=(vx, vy), then the robot is redundant in lambda=3
%
% Copyright (C) 2016, by Arturo Gil Aparicio
%
% This file is part of ARTE (A Robotics Toolbox for Education).
%
% ARTE is free software: you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% ARTE is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU Lesser General Public License for more details.
%
% You should have received a copy of the GNU Leser General Public License
% along with ARTE.  If not, see <http://www.gnu.org/licenses/>.
function null_space_3dofplanar
% link lengths
robot = load_robot('example', '3dofplanar');
q = [pi/2 pi/2 pi/2]';

qs = [];
qds = [];
manips = [];
for i=1:300
    [qb, manip] = null_movement(robot, q);
    q = q + 0.1*qb;
    qs = [qs q];
    qds = [qds qb];
    manips = [manips manip];
end

animate(robot, qs(:,1:15:end))
figure, plot(manips), legend('manipulability')
figure, plot(qs'), legend('q_1', 'q_2', 'q_3')
figure, plot(qds'), legend('qd_1', 'qd_2', 'qd_3')
%q = q + 0.01*ns';

function [ns, manip] = null_movement(robot, q)
J = manipulator_jacobian(robot, q);
% consider only vx, vy
J = J(1:2, :);
iJm = moore_penrose(J);
P = (eye(3)-iJm*J)
% project to null space
ns = P*[1 0 0]';
manip = det(J*J')

function iJm = moore_penrose(J)
iJm = J'*inv(J*J');

repo: ARTE


text:
function [train,B, A] = generate_data(n, d, num_atoms, active_size)
B = cell(num_atoms,1);
for i=1:num_atoms
    x=randn(d)-rand(d); b=x'*x/d+eye(d)*1e-2; B{i}=b/trace(b);
end
train = cell(n,1); A = zeros(num_atoms, n);
for t=1:n
    p=rand(active_size,1);
    idx = randperm(num_atoms, active_size);
    A(idx, t) = p;

    X = zeros(d);
    for s=1:active_size
        X = X + p(s)*B{idx(s)};
    end
    train{t} = X;
end
end

author: hiroyuki-kasai

repo: ClassifierToolbox