Mercurial > hg > octave-image
changeset 864:dac2126ec030
Remove functions deprecated in release 2.2.0.
* bwborder.m, imrotate_Fourier.m, iptcheckstrs.m, impad.m, iptchecknargin.m,
readexif.m, uintlut.m: removed functions which were deprecated in 2.2.0.
* NEWS: list functions removed for next major release (2.4.0).
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Tue, 14 Jan 2014 18:39:28 +0000 |
parents | fa9074c5cfe9 |
children | b42bfcfed81d |
files | NEWS inst/bwborder.m inst/impad.m inst/imrotate_Fourier.m inst/iptchecknargin.m inst/iptcheckstrs.m inst/readexif.m inst/uintlut.m |
diffstat | 8 files changed, 12 insertions(+), 1015 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS +++ b/NEWS @@ -1,3 +1,15 @@ + Summary of important user-visible changes for image 2.4.0 (yyyy/mm/dd): +------------------------------------------------------------------------- + + ** Deprecated functions. + + The following functions were deprecated in image 2.2.0 and have been + removed from image 2.4.0. + + bwborder iptchecknargin readexif + impad iptcheckstrs + imrotate_Fourier uintlut + Summary of important user-visible changes for image 2.2.0 (2014/01/08): -------------------------------------------------------------------------
deleted file mode 100644 --- a/inst/bwborder.m +++ /dev/null @@ -1,51 +0,0 @@ -## Copyright (C) 2000 Etienne Grossmann <etienne@egdn.net> -## -## 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 3 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, see <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {@var{b} = } bwborder (@var{im}) -## Finds the borders of foreground objects in a binary image. -## -## @code{bwborder} has been deprecated in favor of -## @code{bwmorph (@var{im},"remove")}. This function will be removed from -## future versions of the `image' package. -## -## @var{b} is the borders in the 0-1 matrix @var{im}. 4-neighborhood is considered. -## -## A pixel is on the border if it is set in @var{im}, and it has at least one -## neighbor that is not set. -## @end deftypefn - -function b = bwborder(im) - - ## Deprecate bwborder because bwmorph does the same job, works for any - ## number of dimensions, performs faster, and exist in Matlab. - persistent warned = false; - if (! warned) - warned = true; - warning ("Octave:deprecated-function", - ["`bwborder' has been deprecated in favor of " ... - "`bwmorph (IM,\"remove\")'. This function will be removed " ... - "from future versions of the `image' package"]); - endif - -[R,C]=size(im); - -b = im & ... - !([im(2:R,:) ; zeros(1,C) ] & ... - [zeros(1,C); im(1:R-1,:) ] & ... - [im(:,2:C) , zeros(R,1) ] & ... - [zeros(R,1), im(:,1:C-1)] ) ; - -endfunction
deleted file mode 100644 --- a/inst/impad.m +++ /dev/null @@ -1,180 +0,0 @@ -## Copyright (C) 2000 Teemu Ikonen <tpikonen@pcu.helsinki.fi> -## -## 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 3 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, see <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} impad(@var{A}, @var{xpad}, @var{ypad}, [@var{padding}, [@var{const}]]) -## Pad (augment) a matrix for application of image processing algorithms. -## -## This function has been deprecated in favor of @code{padarray} and will be -## removed from future versions of image package. Notes when making -## the conversion: -## -## @itemize @bullet -## @item -## padarray will take the order of the padding arguments by order of dimension, -## i.e., swap @var{xpad} and @var{ypad}. Use -## @code{padarray (@var{A}, [@var{ypad} @var{xpad}], @dots{})} -## -## @item -## There is no @qcode{"ones"} as @var{padding} option. Simply set the value -## 1 as padding value. -## -## @item -## If @var{xpad} and @var{ipad} are 2 element vectors with different values, -## they will need to be replaced by two calls to padarray as follow: -## @group -## @example -## B = padarray (A, [ypad(1) xpad(1)], "pre"); -## B = padarray (B, [ypad(2) xpad(2)], "post"); -## @end example -## @end group -## -## @item -## The @qcode{"reflect"} @var{padding} option of @code{padarray} is different -## from @code{impad}. Use @qcode{"circular"} instead. -## @end itemize -## -## Pads the input image @var{A} with @var{xpad}(1) elements from left, -## @var{xpad}(2), elements from right, @var{ypad}(1) elements from above -## and @var{ypad}(2) elements from below. -## Values of padding elements are determined from the optional arguments -## @var{padding} and @var{const}. @var{padding} is one of -## -## @table @samp -## @item "zeros" -## pad with zeros (default) -## -## @item "ones" -## pad with ones -## -## @item "constant" -## pad with a value obtained from the optional fifth argument const -## -## @item "symmetric" -## pad with values obtained from @var{A} so that the padded image mirrors -## @var{A} starting from edges of @var{A} -## -## @item "reflect" -## same as symmetric, but the edge rows and columns are not used in the padding -## -## @item "replicate" -## pad with values obtained from A so that the padded image -## repeates itself in two dimensions -## -## @end table -## @end deftypefn - -## A nice test matrix for padding: -## A = 10*[1:5]' * ones(1,5) + ones(5,1)*[1:5] - -function retim = impad(im, xpad, ypad, padding = "zeros", const = 1) - - persistent warned = false; - if (! warned) - warned = true; - ## We are deprecating impad because padarray already does the same thing - ## (we don't want multiple functions with the same purpose), padarray - ## already exists in Matlab so it must stay, padarray works for matrices - ## with any number of dimensions, and is now also working faster. - warning ("Octave:deprecated-function", - "`impad' has been deprecated in favor of `padarray (IM, [YPAD XPAD], \"PADDING\")'. This function will be removed from future versions of the `image' package"); - endif - - - ## Input checking - if (!ismatrix(im) || ndims(im) < 2 || ndims(im) > 3) - error("impad: first input argument must be an image"); - endif - if (isscalar(xpad) && xpad >= 0) - xpad(2) = xpad; - elseif (!isreal(xpad) || numel(xpad) != 2 || any(xpad < 0)) - error("impad: xpad must be a positive scalar or 2-vector"); - endif - if (isscalar(ypad) && ypad >= 0) - ypad(2) = ypad; - elseif (!isreal(ypad) || numel(ypad) != 2 || any(ypad < 0)) - error("impad: ypad must be a positive scalar or 2-vector"); - endif - if (!isscalar(const)) - error("impad: fifth input argument must be a scalar"); - endif - - origx = size(im,2); - origy = size(im,1); - retx = origx + xpad(1) + xpad(2); - rety = origy + ypad(1) + ypad(2); - cl = class(im); - - for iter = size(im,3):-1:1 - A = im(:,:,iter); - switch (lower(padding)) - case "zeros" - retval = zeros(rety, retx, cl); - retval(ypad(1)+1 : ypad(1)+origy, xpad(1)+1 : xpad(1)+origx) = A; - case "ones" - retval = ones(rety, retx, cl); - retval(ypad(1)+1 : ypad(1)+origy, xpad(1)+1 : xpad(1)+origx) = A; - case "constant" - retval = const.*ones(rety, retx, cl); - retval(ypad(1)+1 : ypad(1)+origy, xpad(1)+1 : xpad(1)+origx) = A; - case "replicate" - y1 = origy-ypad(1)+1; - x1 = origx-xpad(1)+1; - if (y1 < 1 || x1 < 1 || ypad(2) > origy || xpad(2) > origx) - error("impad: too large padding for this padding type"); - else - yrange1 = y1:origy; - yrange2 = 1:ypad(2); - xrange1 = x1:origx; - xrange2 = 1:xpad(2); - retval = [ A(yrange1, xrange1), A(yrange1, :), A(yrange1, xrange2); - A(:, xrange1), A, A(:, xrange2); - A(yrange2, xrange1), A(yrange2, :), A(yrange2, xrange2) ]; - endif - case "symmetric" - y2 = origy-ypad(2)+1; - x2 = origx-xpad(2)+1; - if (ypad(1) > origy || xpad(1) > origx || y2 < 1 || x2 < 1) - error("impad: too large padding for this padding type"); - else - yrange1 = 1 : ypad(1); - yrange2 = y2 : origy; - xrange1 = 1 : xpad(1); - xrange2 = x2 : origx; - retval = [ fliplr(flipud(A(yrange1, xrange1))), flipud(A(yrange1, :)), fliplr(flipud(A(yrange1, xrange2))); - fliplr(A(:, xrange1)), A, fliplr(A(:, xrange2)); - fliplr(flipud(A(yrange2, xrange1))), flipud(A(yrange2, :)), fliplr(flipud(A(yrange2, xrange2))) ]; - endif - case "reflect" - y2 = origy-ypad(2); - x2 = origx-xpad(2); - if (ypad(1)+1 > origy || xpad(1)+1 > origx || y2 < 1 || x2 < 1) - error("impad: too large padding for this padding type"); - else - yrange1 = 2 : ypad(1)+1; - yrange2 = y2 : origy-1; - xrange1 = 2 : xpad(1)+1; - xrange2 = x2 : origx-1; - retval = [ fliplr(flipud(A(yrange1, xrange1))), flipud(A(yrange1, :)), fliplr(flipud(A(yrange1, xrange2))); - fliplr(A(:, xrange1)), A, fliplr(A(:, xrange2)); - fliplr(flipud(A(yrange2, xrange1))), flipud(A(yrange2, :)), fliplr(flipud(A(yrange2, xrange2))) ]; - endif - otherwise - error("impad: unknown padding type"); - endswitch - - retim(:,:,iter) = retval; - endfor -endfunction
deleted file mode 100644 --- a/inst/imrotate_Fourier.m +++ /dev/null @@ -1,37 +0,0 @@ -## Copyright (C) 2002 Jeff Orchard <jorchard@cs.uwaterloo.ca> -## -## 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 3 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, see <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} imrotate_Fourier (@var{M}, @var{theta}, @var{method}, @var{bbox}) -## Rotation of a 2D matrix. -## -## @emph{This function has been deprecated and will be removed. Instead, use -## @code{imrotate} and select the @code{fourier} method. This function is -## actually just a wrapper to that function.} -## -## @seealso{imrotate} -## @end deftypefn - -function fs = imrotate_Fourier (f, theta, method = "fourier", bbox = "loose") - - persistent warned = false; - if (! warned) - warned = true; - warning ("Octave:deprecated-function", - "`imrotate_Fourier' has been deprecated in favor of `imrotate (M, theta, \"fourier\")'. This function will be removed from future versions of the `image' package"); - endif - fs = imrotate (f, theta, "fourier", bbox) - -endfunction
deleted file mode 100644 --- a/inst/iptchecknargin.m +++ /dev/null @@ -1,81 +0,0 @@ -## Copyright (C) 2011 Carnë Draug <carandraug+dev@gmail.com> -## -## 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 3 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, see <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} iptchecknargin (@var{low}, @var{high}, @var{in}, @var{func_name}) -## Checks for correct number of arguments. -## -## This function has been deprecated. For an exact replacement, use -## @code{narginchk (@var{low}, @var{high})} instead. Alternatively, -## @code{print_usage} is able to provide an even better error message -## provided that there is documentation for the function: -## -## @example -## @group -## if (nargin < min_inputs || nargin > max_inputs) -## print_usage (); -## endif -## @end group -## @end example -## -## This function returns an error unless @var{in} is between the values of -## @var{low} and @var{high}. It does nothing otherwise. They all must be non -## negative scalar integers. @var{high} can also be Inf. -## -## @var{func_name} is the name of the function to be used on the error message. -## -## @seealso{error, nargin, nargout, narginchk, nargoutchk} -## @end deftypefn - -function iptchecknargin (low, high, in, func_name) - - persistent warned = false; - if (! warned) - warned = true; - warning ("Octave:deprecated-function", - "iptchecknargin is obsolete and will be removed from a future version of the image package, please use narginchk instead"); - endif - - if (nargin != 4) - print_usage; - elseif (!isnumeric (low) || !isscalar (low) || !isreal (low) || low < 0 || !isfinite (low) || rem (low, 1) != 0) - error ("Argument 'low' must be a non-negative scalar integer"); - elseif (!isnumeric (high) || !isscalar (high) || !isreal (high) || low < 0 || (isfinite (high) && rem (low, 1) != 0)) - error ("Argument 'high' must be a non-negative scalar integer or Inf"); - elseif (!isnumeric (in) || !isscalar (in) || !isreal (in) || in < 0 || !isfinite (in) || rem (in, 1) != 0) - error ("Argument 'in' must be a non-negative scalar integer"); - elseif (!ischar (func_name)) - error ("Argument 'func_name' must be a string"); - elseif (low > high) - error ("Minimun number of arguments cannot be larger than maximum number of arguments") - endif - - ## error ends in \n so the back trace of the error is not show. This is on - ## purpose since the whole idea of this function is already to give a properly - ## formatted error message - if (in < low) - error ("Function %s expected at least %d input arguments(s) but was called instead with %d input argument(s).\n", ... - func_name, low, in); - elseif (in > high) - error ("Function %s expected at most %d input argument(s) but was called instead with %d input argument(s).\n", ... - func_name, high, in); - endif - -endfunction - -%!test ('iptchecknargin (0, 2, 1, "func")'); # check simple works -%!test ('iptchecknargin (0, Inf, 1, "func")'); # check Inf on max -%!fail ('iptchecknargin (3, 2, 1, "func")'); # check fail min >max -%!fail ('iptchecknargin (2, 3, 1, "func")'); # check fail in out of range
deleted file mode 100644 --- a/inst/iptcheckstrs.m +++ /dev/null @@ -1,76 +0,0 @@ -## Copyright (C) 2011 Carnë Draug <carandraug+dev@gmail.com> -## -## 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 3 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, see <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {@var{valid} =} iptcheckstrs (@var{in}, @var{valid_str}, @var{func_name}, @var{var_name}, @var{pos}) -## Check if argument is a valid string. -## -## This function has been deprecated. Use @code{validatestring} instead. -## -## If @var{in} is not a string, present in the cell array of strings -## @var{valid_str} gives a properly formatted error message. Otherwise, -## @var{valid} is the matched string. The performed matching is case-insensitive. -## -## @var{func_name} is the name of the function to be used on the error message, -## @var{var_name} the name of the argument being checked (for the error message), -## and @var{pos} the position of the argument in the input. -## -## @seealso{strcmp, strcmpi, find, validatestring} -## @end deftypefn - -function out = iptcheckstrs (in, valid_str, func_name, var_name, pos) - - persistent warned = false; - if (! warned) - warned = true; - warning ("Octave:deprecated-function", - "iptcheckstrs is obsolete and will be removed from a future version of the image package, please use validatestring instead"); - endif - - if (nargin != 5) - print_usage; - elseif (!ischar (in)) - error ("Argument 'in' must be a string."); - elseif (!iscellstr (valid_str)) - error ("Argument 'valid_str' must be a cell array of strings."); - elseif (!ischar (func_name)) - error ("Argument 'func_name' must be a string"); - elseif (!ischar (var_name)) - error ("Argument 'var_name' must be a string"); - elseif (!isnumeric (pos) || !isscalar (pos) || !isreal (pos) || pos <= 0 || rem (pos, 1) != 0) - error ("Argument 'pos' must be a real positive integer"); - endif - - idx = find (strcmpi (valid_str, in) == 1, 1, "first"); - - ## error ends in \n so the back trace of the error is not show. This is on - ## purpose since the whole idea of this function is already to give a properly - ## formatted error message - if (isempty (idx)) - valid_str = cellfun (@(x) cstrcat (x, ", "), valid_str, "UniformOutput", false); - valid_str = cstrcat (valid_str{:}); - error("Function %s expected its %s input argument, %s, to match one of these strings:\n\ - %s\n\ - The input, '%s', did not match any of the valid strings.\n", - func_name, iptnum2ordinal (pos), var_name, valid_str(1:end-2), in); - else - out = valid_str{idx}; - endif - -endfunction - -%!assert (iptcheckstrs ("two", {"one", "two", "three"}, "func", "var", 1) == "two" ); # check simple works -%!assert (iptcheckstrs ("Two", {"one", "two", "three"}, "func", "var", 1) == "two" ); # check case insensitive -%!fail ('iptcheckstrs ("four", {"one", "two", "three"}, "func", "var", 1)'); # check failure if not found
deleted file mode 100644 --- a/inst/readexif.m +++ /dev/null @@ -1,539 +0,0 @@ -## Copyright (C) 2009 Roderick Koehle <koehle@users.sourceforge.net> -## -## 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 3 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, see <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {@var{exif} =} readexif(@var{filename}, @var{thumbnail}) -## Read EXIF information from JPEG image data. -## -## The exif tag information are returned in the @var{exif} data structure. -## Integer ratios are expressed as column vector. -## For example, a focal number of 2.8 is expressed -## as FNumber=[28; 10]. Otherwise all data are returned by the type -## as specified in the IFD structures. -## -## The filename for the thumbnail image is optional. -## If given, the thumbnail jpeg image will be stored to -## file @var{thumbnail}. -## -## Reference: -## JEITA CP-3451, Exchangeable image file format for digital still cameras: -## Exif Version 2.2 -## -## @seealso{imwrite, imfinfo} -## @end deftypefn - -function exif = readexif(file, thumbnail) - - if (nargin < 1 || nargin > 2) - print_usage; - endif - persistent warned = false; - if (! warned) - warned = true; - warning ("Octave:deprecated-function", - "`readexif' has been deprecated in favor of `imfinfo'. This function will be removed from future versions of the `image' package"); - endif - - - % Enable the debug flag to see more of the JPG sections. - - debug = false; - - [in, msg] = fopen(file); - if (in<0) - error ("readexif: could not open `%s': %s", file, msg); - end - - s = fread(in, 1, 'uint16', 'ieee-be'); - - JPEG.SOI = 0xffd8; - JPEG.APP0 = 0xffe0; - JPEG.APP1 = 0xffe1; - JPEG.APP2 = 0xffe2; - JPEG.DQT = 0xffdb; - JPEG.DHT = 0xffc4; - JPEG.DRI = 0xffdd; - JPEG.SOF = 0xffc0; - JPEG.SOS = 0xffda; - JPEG.EOI = 0xffd9; - - % Stop if no Start of Image found - - if s~=JPEG.SOI - error('JPEG Format error - missing start of image tag.'); - end - - exif = []; - - while ~feof(in) - s = fread(in, 1, 'uint16', 'ieee-be'); - - switch s - case JPEG.SOI - case JPEG.APP0 - l = fread(in, 1, 'uint16', 'ieee-be'); - if debug, printf('APP0: %i\n', l); end - fseek(in, l-2, 'cof'); - case JPEG.APP1 - l = fread(in, 1, 'uint16', 'ieee-be'); - if debug, printf('APP1: %i\n', l); end - app1 = fread(in, l-2, 'uchar'); - if nargin==1 - exif = parseexif(app1); - else - exif = parseexif(app1, thumbnail); - end - % stop reading further, remove following break - % if you want to extend this parser. - break; - case JPEG.APP2 - l = fread(in, 1, 'uint16', 'ieee-be'); - if debug, printf('APP2: %i\n', l); end - fseek(in, l-2, 'cof'); - case JPEG.DQT % define quantization table - l = fread(in, 1, 'uint16', 'ieee-be'); - if debug, printf('DQT: %i\n', l); end; - fseek(in, l-2, 'cof'); - case JPEG.DHT % define huffmann table - l = fread(in, 1, 'uint16', 'ieee-be'); - fseek(in, l-2, 'cof'); - if debug, printf('DHT: %i\n', l); end - case JPEG.DRI % define restart interoperability - l = fread(in, 1, 'uint16', 'ieee-be'); - fseek(in, l-2, 'cof'); - if debug, printf('DRI: %i\n', l); end - case JPEG.SOF % start of frame - l = fread(in, 1, 'uint16', 'ieee-be'); - fseek(in, l-2, 'cof'); - if debug, printf('SOF: %i\n', l); end - case JPEG.SOS % start of scan - l = fread(in, 1, 'uint16', 'ieee-be'); - fseek(in, l-2, 'cof'); - if debug, printf('SOS: %i\n', l); end - - % JPEG compressed data comes here ... - break; - - case JPEG.EOI % end of image - printf('EOI'); - otherwise % Skip unknown tags - l = fread(in, 1, 'uint16', 'ieee-be'); - if debug, printf('TAG %04X: %i\n', s, l); end - fseek(in, l-2, 'cof'); - end - end - - fclose(in); -end - -% -% Parse EXIF APP1 section -% -% This routine will parse the APP1 section of an jpeg image. -% If a filename "thumb" is given, the tumbnail image data -% will be exported to given file. -% -% exif = parseexif(data, thumb) -% -function exif = parseexif(data, thumb) - - id = char(data(1:6).'); - if strncmp(id, ['Exif' 0 0], 6) - - % TIFF header - - byteorder = char(data(7:8).'); - littleendian = strncmp(byteorder, 'II', 2); - bigendian = strncmp(byteorder, 'MM', 2); - - tag42 = intn(data(9:10), bigendian); - offset = intn(data(11:14), bigendian); - - if (~littleendian && ~bigendian) || tag42~=42 - error('invalid TIFF header'); - end - - % IFD fields - - exif = ifdparse(tifftags(), data, offset, bigendian); - else - exif = []; - end - - % export thumbnail image - - if nargin==2 && isfield(exif, 'JPEGInterchangeFormat') - i = exif.JPEGInterchangeFormat; - n = exif.JPEGInterchangeFormatLength; - - jpg = data(7+i:7+i+n-1); - out = fopen(thumb, 'w'); - if (out<0), - error('Cannot open file "%s" for writing thumbnail image.', thumb); - end - fwrite(out, jpg, 'uint8'); - fclose(out); - end -end - -function ifd = ifdparse(dict, data, offset, endian) - - debug = false; - - ifd = []; - - while offset - ifd_fields = intn(data(7+offset+(0:1)), endian); - - if debug, printf('Tag Type Count Offset\n'); end - for i=1:ifd_fields - j = 9+offset+(i-1)*12; - ifd_tag = intn(data( j:j+1), endian); - ifd_type = intn(data(j+2:j+3), endian); - ifd_count = intn(data(j+4:j+7), endian); - ifd_offset = intn(data(j+8:j+11), endian); - - name = ifdtagname(dict, ifd_tag); - - if debug, - printf('%04x %04x %08x %08x %s : ', ifd_tag, ifd_type, ... - ifd_count, ifd_offset, name); - end - if ifd_type>0 - n = ifdsize(ifd_type); - - if n*ifd_count<=4 - value = data(j+8:j+8+n*ifd_count-1); - value = reshape(value, n, ifd_count); - else - a = 7+ifd_offset; - b = 7+ifd_offset+n*ifd_count-1; - if (a>0 && b>0 && a<=length(data) && b<=length(data)) - value = data(7+ifd_offset:7+ifd_offset+n*ifd_count-1); - value = reshape(value, n, ifd_count); - else - value = []; - end - end - end - - switch ifd_type - case 01 % unsigned char - ifd.(name) = uint8(value); - if debug, - printf('%02x ', uint8(value)); - printf('\n'); - end - case 02 % Ascii - ifd.(name) = char(value); - if debug, printf('%s\n', char(value)); end - case 03 % 16 bit unsigned int - ifd.(name) = uintn(value, endian); - if debug - printf('%i ', intn(value), endian); - printf('\n'); - end - case 04 % 32 bit unsigned int - ifd.(name) = uintn(value, endian); - if debug, printf('%i\n', uintn(value, endian)); end - case 05 % 32 bit unsigned rational - ifd.(name) = [uintn(value(1:4,:), endian); uintn(value(5:8,:), endian)]; - if debug, printf('%i/%i\n',uintn(value(1:4), endian),uintn(value(5:8)), endian); end - case 07 % unknown - ifd.(name) = uint8(value); - if debug - printf('%02x ', value); - printf('\n'); - end - case 09 % 32 bit signed int - ifd.(name) = intn(value, endian); - if debug, printf('%i\n', intn(value, endian)); end - case 10 % 32 bit signed rational - ifd.(name) = [intn(value(1:4,:), endian); intn(value(5:8,:), endian)]; - if debug, printf('%i/%i\n',intn(value(1:4), endian),intn(value(5:8)), endian); end - otherwise - printf('%02x ', value); - printf('\n'); - end - - switch ifd_tag - case 0x8769, % Exif Pointer - ifd.(name) = ifdparse(exiftags(), data, ifd_offset, endian); - case 0x8825, % GPS Pointer - ifd.(name) = ifdparse(gpstags(), data, ifd_offset, endian); - case 0xa005 % Interoperatibility Pointer - ifd.(name) = ifdparse(dict, data, ifd_offset, endian); -% case 0x927c % Makernotes -% ifd.(name) = ifdparse([], data, ifd_offset, endian); - otherwise - end - end - j = 9+offset+ifd_fields*12; - ifd_next = intn(data(j:j+3), endian); - - offset = ifd_next; - end -end - -% -% Return bytelength for respective IFD type -% -function n = ifdsize(ifd_type) - switch ifd_type - case {1, 2, 7}, n = 1; - case 03 , n = 2; - case {4, 9} , n = 4; - case {5, 10} , n = 8; - otherwise , n = 1; - end -end - - -% -% Convert little endian character vector to integer -% -function y = intn(x, bigendian) - if bigendian - y = polycol(x, int32(256)); - else - y = polycol(flipud(x), int32(256)); - end -end - -function y = uintn(x, bigendian) - if bigendian - y = polycol(x, uint32(256)); - else - y = polycol(flipud(x), uint32(256)); - end -end - -% -% Use own polyval that works with integers, -% it evaluates the number polygon columnwise. -% -% number = polycol(digits, base) -% -function y = polycol(c, x) - y = c(1,:); - for i=2:size(c, 1) - y = y.*x+c(i,:); - end -end - -% -% Query EXIF IFD tagname -% -% Unfortunately, neither MATLAB nor Octave provide a hash functionality, -% so use structures as hash. -% -function name = ifdtagname(dict, key) - k = sprintf('K%04X', key); - if isfield(dict, k) - name = dict.(k); - else - name = sprintf('tag%04X', key); - end -end - -% -% Primary image IFD tags according to Exif 2.2 -% -function dict = tifftags() - t = { - - % TIFF Tags according to EXIF2.2, additional baseline TIFF tags are marked by a '%' - - '0FE' 'NewSubfileType' % - '0FF' 'SubfileType' % - '100' 'ImageWidth' - '101' 'ImageLength' - '102' 'BitsPerSample' - '103' 'Compression' - '106' 'PhotometricInterpretation' - '108' 'CellWidth' % - '109' 'CellLength' % - '10A' 'FillOrder' % - '10E' 'ImageDescription' - '10F' 'Make' - '110' 'Model' - '111' 'StripOffsets' - '112' 'Orientation' - '115' 'SamplesPerPixel' - '116' 'RowsPerStrip' - '117' 'StripByteCounts' - '118' 'MinSampleValue' % - '119' 'MaxSampleValue' % - '11A' 'XResolution' - '11B' 'YResolution' - '11C' 'PlanarConfiguration' - '120' 'FreeOffsets' % - '121' 'FreeByteCounts' % - '122' 'GrayResponseUnit' % - '123' 'GrayResponseCurve' % - '128' 'ResolutionUnit' - '12D' 'TransferFunction' - '131' 'Software' - '132' 'DateTime' - '13B' 'Artist' - '13C' 'HostComputer' % - '13E' 'WhitePoint' - '13F' 'PrimaryChromaticities' - '140' 'ColorMap' % - '152' 'ExtraSamples' % - '201' 'JPEGInterchangeFormat' - '202' 'JPEGInterchangeFormatLength' - '211' 'YCbCrCoefficients' - '212' 'YCbCrSubSampling' - '213' 'YCbCrPositioning' - '214' 'ReferenceBlackWhite' - '8298' 'Copyright' - '8769' 'Exif IFD Pointer' - '8825' 'GPS Info IFD Pointer' - }; - - dict = []; - for i=1:size(t,1) - key = sprintf('K%04X', hex2dec(t{i,1})); - value = t{i,2}; - dict.(key) = strrep(value, ' ', '_'); - end -end - -% -% EXIF private tags -% -function dict = exiftags() - t = { - - % EXIF Tags - - '829A' 'ExposureTime' - '829D' 'FNumber' - '8822' 'ExposureProgram' - '8824' 'SpectralSensitivity' - '8827' 'ISOSpeedRatings' - '8828' 'OECF' - '9000' 'ExifVersion' - '9003' 'DateTimeOriginal' - '9004' 'DateTimeDigitized' - '9101' 'ComponentsConfiguration' - '9102' 'CompressedBitsPerPixel' - '9201' 'ShutterSpeedValue' - '9202' 'ApertureValue' - '9203' 'BrightnessValue' - '9204' 'ExposureBiasValue' - '9205' 'MaxApertureValue' - '9206' 'SubjectDistance' - '9207' 'MeteringMode' - '9208' 'LightSource' - '9209' 'Flash' - '920A' 'FocalLength' - '9214' 'SubjectArea' - '927C' 'MakerNote' - '9286' 'UserComment' - '9290' 'SubsecTime' - '9291' 'SubsecTimeOriginal' - '9292' 'SubsecTimeDigitized' - 'A000' 'FlashpixVersion' - 'A001' 'ColorSpace' - 'A002' 'PixelXDimension' - 'A003' 'PixelYDimension' - 'A004' 'RelatedSoundFile' - 'A005' 'Interoperatibility IFD Pointer' - 'A20B' 'FlashEnergy' - 'A20C' 'SpatialFrequencyResponse' - 'A20E' 'FocalPlaneXResolution' - 'A20F' 'FocalPlaneYResolution' - 'A210' 'FocalPlaneResolutionUnit' - 'A214' 'SubjectLocation' - 'A215' 'ExposureIndex' - 'A217' 'SensingMethod' - 'A300' 'FileSource' - 'A301' 'SceneType' - 'A302' 'CFAPattern' - 'A401' 'CustomRendered' - 'A402' 'ExposureMode' - 'A403' 'WhiteBalance' - 'A404' 'DigitalZoomRatio' - 'A405' 'FocalLengthIn35mmFilm' - 'A406' 'SceneCaptureType' - 'A407' 'GainControl' - 'A408' 'Contrast' - 'A409' 'Saturation' - 'A40A' 'Sharpness' - 'A40B' 'DeviceSettingDescription' - 'A40C' 'SubjectDistanceRange' - 'A420' 'ImageUniqueID' - - % Interoperatibility tags - - '001' 'InteroperatibilityIndex' - '002' 'InteroperatibilityVersion' - '1000' 'RelatedImageFileFormat' - '1001' 'RelatedImageWidth' - '1002' 'RelatedImageLength' - }; - - dict = []; - for i=1:size(t,1) - key = sprintf('K%04X', hex2dec(t{i,1})); - value = t{i,2}; - dict.(key) = strrep(value, ' ', '_'); - end -end - -% -% EXIF GPS tags -% -function dict = gpstags() - t = { - 0 'GPSVersionID' - 1 'GPSLatitudeRef' - 2 'GPSLatitude' - 3 'GPSLongitudeRef' - 4 'GPSLongitude' - 5 'GPSAltitudeRef' - 6 'GPSAltitude' - 7 'GPSTimeStamp' - 8 'GPSSatellites' - 9 'GPSStatus' - 10 'GPSMeasureMode' - 11 'GPSDOP' - 12 'GPSSpeedRef' - 13 'GPSSpeed' - 14 'GPSTrackRef' - 15 'GPSTrack' - 16 'GPSImgDirectionRef' - 17 'GPSImgDirection' - 18 'GPSMapDatum' - 19 'GPSDestLatitudeRef' - 20 'GPSDestLatitude' - 21 'GPSDestLongitudeRef' - 22 'GPSDestLongitude' - 23 'GPSDestBearingRef' - 24 'GPSDestBearing' - 25 'GPSDestDistanceRef' - 26 'GPSDestDistance' - }; - - dict = []; - for i=1:size(t,1) - key = sprintf('K%04X', t{i,1}); - value = t{i,2}; - dict.(key) = strrep(value, ' ', '_'); - end -end -
deleted file mode 100644 --- a/inst/uintlut.m +++ /dev/null @@ -1,51 +0,0 @@ -## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com> -## -## 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 3 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, see <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {@var{B} =} uintlut (@var{A}, @var{LUT}) -## Computes matrix B by using A as an index to lookup table LUT. -## -## This function has been deprecated. Use @code{intlut} instead. -## -## B = uintlut(A, LUT) calculates a matrix B by using @var{LUT} as a -## lookup table indexed by values in @var{A}. -## -## B class is the same as @var{LUT}. -## @end deftypefn - -function B = uintlut (A, LUT) - if (nargin != 2) - print_usage; - endif - persistent warned = false; - if (! warned) - warned = true; - warning ("Octave:deprecated-function", - ["`uintlut' has been deprecated in favor of `intlut'. This " ... - "function will be removed from future versions of the `image'" ... - " package"]); - endif - - B = LUT(A); -endfunction - -%!demo -%! uintlut(uint8([1,2,3,4]),uint8([255:-1:0])); -%! % Returns a uint8 array [255,254,253,252] - -%!assert(uintlut(uint8([1,2,3,4]),uint8([255:-1:0])), uint8([255:-1:252])); -%!assert(uintlut(uint16([1,2,3,4]),uint16([255:-1:0])), uint16([255:-1:252])); -%!assert(uintlut(uint32([1,2,3,4]),uint32([255:-1:0])), uint32([255:-1:252])); -%!assert(uintlut(uint64([1,2,3,4]),uint64([255:-1:0])), uint64([255:-1:252]));