1## Copyright (C) 2018 Martin Janda <janda.martin1@gmail.com> 2## 3## This program is free software: you can redistribute it and/or modify it 4## under the terms of the GNU General Public License as published by 5## the Free Software Foundation, either version 3 of the License, or 6## (at your option) any later version. 7## 8## This program is distributed in the hope that it will be useful, but 9## WITHOUT ANY WARRANTY; without even the implied warranty of 10## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11## GNU General Public License for more details. 12## 13## You should have received a copy of the GNU General Public License 14## along with this program. If not, see 15## <https://www.gnu.org/licenses/>. 16 17## -*- texinfo -*- 18## @deftypefn {} {@var{TF} =} sizesMatch (@var{r}, @var{A}) 19## Determine if object and image are size-compatible. 20## 21## Outputs logical 1 (true) if the first two dimensions of an n-dimensional 22## image @var{A} match the image size of the spatial referencing object @var{r}, 23## otherwise outputs zero (false). 24## 25## @seealso{imref2d, imref3d} 26## @end deftypefn 27 28function TF = sizesMatch (r, A) 29 if (nargin != 2) 30 print_usage(); 31 endif 32 33 sizeA = size(A); 34 TF = all(sizeA(1:2) == r.ImageSize); 35endfunction 36 37%!error id=Octave:invalid-fun-call sizesMatch (imref2d) 38 39## example from MATLAB documentation 40%!test 41%! I = zeros (256, 256); 42%! r = imref2d ([256, 256]); 43%! assert (sizesMatch (r, I), true) 44%! I2 = zeros (246, 300); 45%! assert (sizesMatch (r, I2), false) 46 47## accepts empty image 48%!test 49%! r = imref2d ([256, 256]); 50%! assert (sizesMatch (r, []), false) 51 52## accepts 1-D image 53%!test 54%! r = imref2d ([256, 256]); 55%! assert (sizesMatch (r, 42), false) 56 57## accepts N-D image 58%!test 59%! r = imref2d ([256, 256]); 60%! assert (sizesMatch (r, zeros (256, 256, 3, 2)), true) 61 62%!test 63%! I = zeros (384, 512, 3); 64%! r = imref2d (size (I)); 65%! assert (sizesMatch (r, I), true)