PageRenderTime 36ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kvequal.m

http://github.com/aludnam/MATLAB
Objective C | 191 lines | 188 code | 3 blank | 0 comment | 60 complexity | ec0e73613448c341bbb13cb5bf74d2e0 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kvequal 'Informs if two images are equal'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros vequal.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Input Image #1', required: 'input file'
  6. % String: v 'Data Variable Name:', default: ' ': 'variable'
  7. % OutputFile: o 'Output File', required: 'The first input file'
  8. % InputFile: i2 'Input Image #2', optional: 'input file'
  9. % Integer: c 'Constant Image', default: 0: 'constant value'
  10. %
  11. % Example: o = kvequal({i1, i2}, {'i1','';'v',' ';'o','';'i2','';'c',0})
  12. %
  13. % Khoros helpfile follows below:
  14. %
  15. % PROGRAM
  16. % vequal - Informs if two images are equal
  17. %
  18. % DESCRIPTION
  19. % .I vequal
  20. % compares two images pixel by pixel and informs if they are equal. In case that the images are equal, it returns a variable affect by the value 1, otherwise this variable is affected by the value 0. An optional constant image can be entered instead of image2.
  21. %
  22. % The two input images must be of the same size and have the same number of data bands. The input images may be of the same or different data types. If the input
  23. % images are of different data types, then all input images will be upcast to the highest input image data type.
  24. %
  25. %
  26. %
  27. % EXAMPLES
  28. % vequal -i1 image1.xv -i2 image2.xv -v flag
  29. %
  30. % "SEE ALSO"
  31. % vcast1(1)
  32. %
  33. % RESTRICTIONS
  34. % .I vequal
  35. % works for all data types supported by Khoros, but for the moment it is implemented only for bit and unsigned char images.
  36. %
  37. % REFERENCES
  38. %
  39. % COPYRIGHT
  40. % Copyright (C) 1993-1997 Junior Barrera, Roberto Lotufo. All rights reserved.
  41. %
  42. function varargout = kvequal(varargin)
  43. if nargin ==0
  44. Inputs={};arglist={'',''};
  45. elseif nargin ==1
  46. Inputs=varargin{1};arglist={'',''};
  47. elseif nargin ==2
  48. Inputs=varargin{1}; arglist=varargin{2};
  49. else error('Usage: [out1,..] = kvequal(Inputs,arglist).');
  50. end
  51. if size(arglist,2)~=2
  52. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  53. end
  54. narglist={'i1', '__input';'v', ' ';'o', '__output';'i2', '__input';'c', 0};
  55. maxval={0,0,0,1,255};
  56. minval={0,0,0,1,0};
  57. istoggle=[0,0,0,1,1];
  58. was_set=istoggle * 0;
  59. paramtype={'InputFile','String','OutputFile','InputFile','Integer'};
  60. % identify the input arrays and assign them to the arguments as stated by the user
  61. if ~iscell(Inputs)
  62. Inputs = {Inputs};
  63. end
  64. NumReqOutputs=1; nextinput=1; nextoutput=1;
  65. for ii=1:size(arglist,1)
  66. wasmatched=0;
  67. for jj=1:size(narglist,1)
  68. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  69. wasmatched = 1;
  70. was_set(jj) = 1;
  71. if strcmp(narglist{jj,2}, '__input')
  72. if (nextinput > length(Inputs))
  73. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  74. end
  75. narglist{jj,2} = 'OK_in';
  76. nextinput = nextinput + 1;
  77. elseif strcmp(narglist{jj,2}, '__output')
  78. if (nextoutput > nargout)
  79. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  80. end
  81. if (isempty(arglist{ii,2}))
  82. narglist{jj,2} = 'OK_out';
  83. else
  84. narglist{jj,2} = arglist{ii,2};
  85. end
  86. nextoutput = nextoutput + 1;
  87. if (minval{jj} == 0)
  88. NumReqOutputs = NumReqOutputs - 1;
  89. end
  90. elseif isstr(arglist{ii,2})
  91. narglist{jj,2} = arglist{ii,2};
  92. else
  93. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  94. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  95. end
  96. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  97. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  98. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  99. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  100. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  101. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  102. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  103. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  104. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  105. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  106. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  107. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  108. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  109. end
  110. end
  111. end
  112. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  113. narglist{jj,2} = arglist{ii,2};
  114. end
  115. end
  116. end
  117. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  118. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  119. end
  120. end
  121. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  122. for jj=1:size(narglist,1)
  123. if strcmp(paramtype{jj}, 'Toggle')
  124. if (narglist{jj,2} ==0)
  125. narglist{jj,1} = '';
  126. end;
  127. narglist{jj,2} = '';
  128. end;
  129. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  130. narglist{jj,1} = '';
  131. narglist{jj,2} = '';
  132. end;
  133. if strcmp(narglist{jj,2}, '__input')
  134. if (minval{jj} == 0) % meaning this input is required
  135. if (nextinput > size(Inputs))
  136. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  137. else
  138. narglist{jj,2} = 'OK_in';
  139. nextinput = nextinput + 1;
  140. end
  141. else % this is an optional input
  142. if (nextinput <= length(Inputs))
  143. narglist{jj,2} = 'OK_in';
  144. nextinput = nextinput + 1;
  145. else
  146. narglist{jj,1} = '';
  147. narglist{jj,2} = '';
  148. end;
  149. end;
  150. else
  151. if strcmp(narglist{jj,2}, '__output')
  152. if (minval{jj} == 0) % this is a required output
  153. if (nextoutput > nargout & nargout > 1)
  154. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  155. else
  156. narglist{jj,2} = 'OK_out';
  157. nextoutput = nextoutput + 1;
  158. NumReqOutputs = NumReqOutputs-1;
  159. end
  160. else % this is an optional output
  161. if (nargout - nextoutput >= NumReqOutputs)
  162. narglist{jj,2} = 'OK_out';
  163. nextoutput = nextoutput + 1;
  164. else
  165. narglist{jj,1} = '';
  166. narglist{jj,2} = '';
  167. end;
  168. end
  169. end
  170. end
  171. end
  172. if nargout
  173. varargout = cell(1,nargout);
  174. else
  175. varargout = cell(1,1);
  176. end
  177. global KhorosRoot
  178. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  179. w=['"' KhorosRoot];
  180. else
  181. if ispc
  182. w='"C:\Program Files\dip\khorosBin\';
  183. else
  184. [s,w] = system('which cantata');
  185. w=['"' w(1:end-8)];
  186. end
  187. end
  188. [varargout{:}]=callKhoros([w 'vequal" '],Inputs,narglist);