/matlab_tools/Converted/kvqerr.m

http://github.com/aludnam/MATLAB · Objective C · 201 lines · 198 code · 3 blank · 0 comment · 54 complexity · 0796fc326d91bae30300de1308f5cdc4 MD5 · raw file

  1. %kvqerr 'Compute Error between Quantized Image and Original (K1)'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros vqerr.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Quantized image', required: 'Quantized image'
  6. % InputFile: i2 'Original image', required: 'Original image'
  7. % InputFile: m 'Masking Image', optional: 'operation masking image'
  8. % OutputFile: o 'Output ASCII File', required: 'Output ASCII File'
  9. %
  10. % Example: o = kvqerr({i1, i2, m}, {'i1','';'i2','';'m','';'o',''})
  11. %
  12. % Khoros helpfile follows below:
  13. %
  14. % PROGRAM
  15. % vqerr - Compute Error between Quantized Image and Original (K1)
  16. %
  17. % DESCRIPTION
  18. % .I vqerr
  19. % computes the RMS quantization error between a quantized image and the original
  20. % image.
  21. %
  22. % The first input image is the quantized image and should have maps attached.
  23. % The data type of the first image should be BYTE or INT.
  24. % The map should be of the same data type as the data in the second image
  25. % (the original). The second (original) image should have no maps attached.
  26. %
  27. % The number of columns in the map of the first input image should match the
  28. % number of bands in the second (original) input image.
  29. %
  30. %
  31. %
  32. % EXAMPLES
  33. % % igamut -i mandril.rgb.xv -o mandril.quant
  34. % & kformats -i mandril.quant -o mandril.quant -xvimage
  35. % % vqerr -i1 mandril.quant -i2 mandril.rgb.xv -o mandril.new
  36. %
  37. % will quantize the color mandril image and compute the quantization
  38. % error.
  39. %
  40. % "SEE ALSO"
  41. % vipl(3),vquant(1),igamut
  42. %
  43. % RESTRICTIONS
  44. % .I vqerr
  45. % will not operate on BIT, COMPLEX, or DOUBLE data storage types.
  46. %
  47. % REFERENCES
  48. %
  49. % COPYRIGHT
  50. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  51. %
  52. function varargout = kvqerr(varargin)
  53. if nargin ==0
  54. Inputs={};arglist={'',''};
  55. elseif nargin ==1
  56. Inputs=varargin{1};arglist={'',''};
  57. elseif nargin ==2
  58. Inputs=varargin{1}; arglist=varargin{2};
  59. else error('Usage: [out1,..] = kvqerr(Inputs,arglist).');
  60. end
  61. if size(arglist,2)~=2
  62. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  63. end
  64. narglist={'i1', '__input';'i2', '__input';'m', '__input';'o', '__output'};
  65. maxval={0,0,1,0};
  66. minval={0,0,1,0};
  67. istoggle=[0,0,1,0];
  68. was_set=istoggle * 0;
  69. paramtype={'InputFile','InputFile','InputFile','OutputFile'};
  70. % identify the input arrays and assign them to the arguments as stated by the user
  71. if ~iscell(Inputs)
  72. Inputs = {Inputs};
  73. end
  74. NumReqOutputs=1; nextinput=1; nextoutput=1;
  75. for ii=1:size(arglist,1)
  76. wasmatched=0;
  77. for jj=1:size(narglist,1)
  78. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  79. wasmatched = 1;
  80. was_set(jj) = 1;
  81. if strcmp(narglist{jj,2}, '__input')
  82. if (nextinput > length(Inputs))
  83. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  84. end
  85. narglist{jj,2} = 'OK_in';
  86. nextinput = nextinput + 1;
  87. elseif strcmp(narglist{jj,2}, '__output')
  88. if (nextoutput > nargout)
  89. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  90. end
  91. if (isempty(arglist{ii,2}))
  92. narglist{jj,2} = 'OK_out';
  93. else
  94. narglist{jj,2} = arglist{ii,2};
  95. end
  96. nextoutput = nextoutput + 1;
  97. if (minval{jj} == 0)
  98. NumReqOutputs = NumReqOutputs - 1;
  99. end
  100. elseif isstr(arglist{ii,2})
  101. narglist{jj,2} = arglist{ii,2};
  102. else
  103. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  104. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  105. end
  106. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  107. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  108. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  109. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  110. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  111. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  112. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  113. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  114. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  115. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  116. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  117. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  118. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  119. end
  120. end
  121. end
  122. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  123. narglist{jj,2} = arglist{ii,2};
  124. end
  125. end
  126. end
  127. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  128. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  129. end
  130. end
  131. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  132. for jj=1:size(narglist,1)
  133. if strcmp(paramtype{jj}, 'Toggle')
  134. if (narglist{jj,2} ==0)
  135. narglist{jj,1} = '';
  136. end;
  137. narglist{jj,2} = '';
  138. end;
  139. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  140. narglist{jj,1} = '';
  141. narglist{jj,2} = '';
  142. end;
  143. if strcmp(narglist{jj,2}, '__input')
  144. if (minval{jj} == 0) % meaning this input is required
  145. if (nextinput > size(Inputs))
  146. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  147. else
  148. narglist{jj,2} = 'OK_in';
  149. nextinput = nextinput + 1;
  150. end
  151. else % this is an optional input
  152. if (nextinput <= length(Inputs))
  153. narglist{jj,2} = 'OK_in';
  154. nextinput = nextinput + 1;
  155. else
  156. narglist{jj,1} = '';
  157. narglist{jj,2} = '';
  158. end;
  159. end;
  160. else
  161. if strcmp(narglist{jj,2}, '__output')
  162. if (minval{jj} == 0) % this is a required output
  163. if (nextoutput > nargout & nargout > 1)
  164. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  165. else
  166. narglist{jj,2} = 'OK_out';
  167. nextoutput = nextoutput + 1;
  168. NumReqOutputs = NumReqOutputs-1;
  169. end
  170. else % this is an optional output
  171. if (nargout - nextoutput >= NumReqOutputs)
  172. narglist{jj,2} = 'OK_out';
  173. nextoutput = nextoutput + 1;
  174. else
  175. narglist{jj,1} = '';
  176. narglist{jj,2} = '';
  177. end;
  178. end
  179. end
  180. end
  181. end
  182. if nargout
  183. varargout = cell(1,nargout);
  184. else
  185. varargout = cell(1,1);
  186. end
  187. global KhorosRoot
  188. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  189. w=['"' KhorosRoot];
  190. else
  191. if ispc
  192. w='"C:\Program Files\dip\khorosBin\';
  193. else
  194. [s,w] = system('which cantata');
  195. w=['"' w(1:end-8)];
  196. end
  197. end
  198. [varargout{:}]=callKhoros([w 'vqerr" '],Inputs,narglist);