X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=utilities_ESRF%2Fcut.m;fp=utilities_ESRF%2Fcut.m;h=007e8e800869c1e50b52d4c22a733578b016d1fe;hp=0000000000000000000000000000000000000000;hb=99b9890c11d31f9ae22dd481873e01c708175073;hpb=d0401c49b6b7511cfdaa0534b78bd3c5b2b0637a diff --git a/utilities_ESRF/cut.m b/utilities_ESRF/cut.m new file mode 100644 index 0000000..007e8e8 --- /dev/null +++ b/utilities_ESRF/cut.m @@ -0,0 +1,60 @@ +## Copyright (C) 2012 P. Cloetens +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program 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 General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +## cut +## function imcut = cut(im, nn, mn[, cnn, cmn]) +## cuts a sub-matrix out of a larger matrix +## cuts in the center of the original matrix, except if new center is specified +## NO CHECKING of validity indices sub-matrix! +## +## arguments: +## argument 1: original matrix im +## argument 2: number of rows in result +## argument 3: number of columns in result +## argument 4: center row around which to cut ( default: center ) +## argument 5: center column around which to cut ( default: center ) +## +## examples: +## im_roi = cut(im, 1024, 1024) -> cut center 1024x1024 pixels +## im_roi = cut(im, 1024, 1024, 600.5, 700.5) -> cut 1024x1024 pixels around pixels (600-601, 700-701) + +## Author: P. Cloetens +## +## 2012-10-14 P. Cloetens +## * Initial revision + +function imcut = cut(im, nn, mn, cnn, cmn) + if !exist('cnn', 'var') + cnn = []; + endif + if !exist('cmn', 'var') + cmn = []; + endif + + [n,m] = size(im); + if isempty(cnn) + cnn = (n+1)/2; + endif + if isempty(cmn) + cmn = (m+1)/2; + endif + + rb = round(0.5+cnn-nn/2); + re = nn+rb-1; + cb = round(0.5+cmn-mn/2); + ce = mn+cb-1; + imcut = im(rb:re, cb:ce); +endfunction