PageRenderTime 50ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kvcast1.m

http://github.com/aludnam/MATLAB
Objective C | 229 lines | 226 code | 3 blank | 0 comment | 55 complexity | fe291b4dd1041bcfcc63fb5f3eada6ff MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kvcast1 'Upcast Images to the Highest Input Data Type'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros vcast1.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Input Image #1', required: 'input image #1'
  6. % InputFile: i2 'Input Image #2', required: 'input image #2'
  7. % InputFile: i3 'Input Image #3', optional: 'input image #3'
  8. % InputFile: i4 'Input Image #4', optional: 'input image #4'
  9. % InputFile: i5 'Input Image #5', optional: 'input image #5'
  10. % OutputFile: o1 'Output Image #1', required: 'output image #1'
  11. % OutputFile: o2 'Output Image #2', required: 'output image #2'
  12. % OutputFile: o3 'Output Image #3', optional: 'output image #3'
  13. % OutputFile: o4 'Output Image #4', optional: 'output image #4'
  14. % OutputFile: o5 'Output Image #5', optional: 'output image #5'
  15. % MultiChoice: t 'Select Data Type (Auto Upcast if Not Selected)', default: 1: 'choose byte data type'
  16. % String: t 'Byte', default: 'byte': 'choose integer data type'
  17. % String: t 'Integer', default: 'int': 'choose complex data type'
  18. % String: t 'Complex', default: 'complex': 'choose short data type'
  19. % String: t 'Short', default: 'short': 'choose float data type'
  20. % String: t 'Float', default: 'float': 'choose double data type'
  21. % String: t 'Double', default: 'double': 'Select data type [default = Auto Upcast to Highest Input Data Type]'
  22. % Choices are:
  23. %
  24. % Example: [o1, o2, o3, o4, o5] = kvcast1({i1, i2, i3, i4, i5}, {'i1','';'i2','';'i3','';'i4','';'i5','';'o1','';'o2','';'o3','';'o4','';'o5','';'t',1;'t','byte';'t','int';'t','complex';'t','short';'t','float';'t','double'})
  25. %
  26. % Khoros helpfile follows below:
  27. %
  28. % PROGRAM
  29. % vcast1 - Upcast Images to the Highest Input Data Type
  30. %
  31. % DESCRIPTION
  32. % .I vcast1
  33. % This is a modified version of Khoros' vcast. Scaling and Normalization are turned off, so that BIT to BYTE_1 conversion yields pixel values of 0 or 255 on the BYTE image.
  34. % will upconvert or upcast each input image to the highest input image
  35. % data type. Optionally, the user may elect to upcast all images to
  36. % a specified data type, as long as it is a data type that is equal to
  37. % or greater than the highest data type of the input images. If the
  38. % user tries to select a data type that is lower than the highest
  39. % data type of the input images, an error message will be produced
  40. % indicating that down casting is not allowed.
  41. %
  42. % There are no restrictions as to the input image data types. The data
  43. % types can range from BIT to DOUBLE. The input images may contain any
  44. % combination of sizes or number of data bands. All map information from
  45. % each input image is transferred to the corresponding output image.
  46. %
  47. % Note that when converting from type BIT to BYTE, the output values
  48. % will be 0 or 1. This is different from the results one would obtain
  49. % using the defaults with vconvert. In trying to preserve the
  50. % integrity of the data, vcast1 scales the data by 1.
  51. %
  52. %
  53. %
  54. % EXAMPLES
  55. % vcast1 -i1 image.bit -i2 image.float -o1 image1 -o2 image2
  56. %
  57. % converts both input images to data type FLOAT. The optional data
  58. % type argument was not selected, so auto convert was used to cast
  59. % both images to the highest data type of the input images (in this case
  60. % FLOAT).
  61. %
  62. % vcast1 -i1 image.bit -i2 image.byte -i3 image.short -o1 img1 -o2 img2 -o3 img3 -t float
  63. %
  64. % converts each input image to data type FLOAT. The optional data
  65. % type argument was used to upcast all input images to data type
  66. % FLOAT.
  67. %
  68. % "SEE ALSO"
  69. % vconvert(1)
  70. %
  71. % RESTRICTIONS
  72. % .I vcast1
  73. % only scales the input data by 1, and will only upconvert the data.
  74. %
  75. % REFERENCES
  76. %
  77. % COPYRIGHT
  78. % Copyright (C) 1993-1997 Junior Barrera, Roberto Lotufo. All rights reserved.
  79. %
  80. function varargout = kvcast1(varargin)
  81. if nargin ==0
  82. Inputs={};arglist={'',''};
  83. elseif nargin ==1
  84. Inputs=varargin{1};arglist={'',''};
  85. elseif nargin ==2
  86. Inputs=varargin{1}; arglist=varargin{2};
  87. else error('Usage: [out1,..] = kvcast1(Inputs,arglist).');
  88. end
  89. if size(arglist,2)~=2
  90. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  91. end
  92. narglist={'i1', '__input';'i2', '__input';'i3', '__input';'i4', '__input';'i5', '__input';'o1', '__output';'o2', '__output';'o3', '__output';'o4', '__output';'o5', '__output';'t', 1;'t', 'byte';'t', 'int';'t', 'complex';'t', 'short';'t', 'float';'t', 'double'};
  93. maxval={0,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0};
  94. minval={0,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0};
  95. istoggle=[0,0,1,1,1,0,0,1,1,1,0,1,1,1,1,1,1];
  96. was_set=istoggle * 0;
  97. paramtype={'InputFile','InputFile','InputFile','InputFile','InputFile','OutputFile','OutputFile','OutputFile','OutputFile','OutputFile','MultiChoice','String','String','String','String','String','String'};
  98. % identify the input arrays and assign them to the arguments as stated by the user
  99. if ~iscell(Inputs)
  100. Inputs = {Inputs};
  101. end
  102. NumReqOutputs=2; nextinput=1; nextoutput=1;
  103. for ii=1:size(arglist,1)
  104. wasmatched=0;
  105. for jj=1:size(narglist,1)
  106. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  107. wasmatched = 1;
  108. was_set(jj) = 1;
  109. if strcmp(narglist{jj,2}, '__input')
  110. if (nextinput > length(Inputs))
  111. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  112. end
  113. narglist{jj,2} = 'OK_in';
  114. nextinput = nextinput + 1;
  115. elseif strcmp(narglist{jj,2}, '__output')
  116. if (nextoutput > nargout)
  117. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  118. end
  119. if (isempty(arglist{ii,2}))
  120. narglist{jj,2} = 'OK_out';
  121. else
  122. narglist{jj,2} = arglist{ii,2};
  123. end
  124. nextoutput = nextoutput + 1;
  125. if (minval{jj} == 0)
  126. NumReqOutputs = NumReqOutputs - 1;
  127. end
  128. elseif isstr(arglist{ii,2})
  129. narglist{jj,2} = arglist{ii,2};
  130. else
  131. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  132. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  133. end
  134. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  135. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  136. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  137. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  138. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  139. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  140. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  141. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  142. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  143. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  144. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  145. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  146. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  147. end
  148. end
  149. end
  150. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  151. narglist{jj,2} = arglist{ii,2};
  152. end
  153. end
  154. end
  155. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  156. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  157. end
  158. end
  159. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  160. for jj=1:size(narglist,1)
  161. if strcmp(paramtype{jj}, 'Toggle')
  162. if (narglist{jj,2} ==0)
  163. narglist{jj,1} = '';
  164. end;
  165. narglist{jj,2} = '';
  166. end;
  167. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  168. narglist{jj,1} = '';
  169. narglist{jj,2} = '';
  170. end;
  171. if strcmp(narglist{jj,2}, '__input')
  172. if (minval{jj} == 0) % meaning this input is required
  173. if (nextinput > size(Inputs))
  174. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  175. else
  176. narglist{jj,2} = 'OK_in';
  177. nextinput = nextinput + 1;
  178. end
  179. else % this is an optional input
  180. if (nextinput <= length(Inputs))
  181. narglist{jj,2} = 'OK_in';
  182. nextinput = nextinput + 1;
  183. else
  184. narglist{jj,1} = '';
  185. narglist{jj,2} = '';
  186. end;
  187. end;
  188. else
  189. if strcmp(narglist{jj,2}, '__output')
  190. if (minval{jj} == 0) % this is a required output
  191. if (nextoutput > nargout & nargout > 1)
  192. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  193. else
  194. narglist{jj,2} = 'OK_out';
  195. nextoutput = nextoutput + 1;
  196. NumReqOutputs = NumReqOutputs-1;
  197. end
  198. else % this is an optional output
  199. if (nargout - nextoutput >= NumReqOutputs)
  200. narglist{jj,2} = 'OK_out';
  201. nextoutput = nextoutput + 1;
  202. else
  203. narglist{jj,1} = '';
  204. narglist{jj,2} = '';
  205. end;
  206. end
  207. end
  208. end
  209. end
  210. if nargout
  211. varargout = cell(1,nargout);
  212. else
  213. varargout = cell(1,1);
  214. end
  215. global KhorosRoot
  216. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  217. w=['"' KhorosRoot];
  218. else
  219. if ispc
  220. w='"C:\Program Files\dip\khorosBin\';
  221. else
  222. [s,w] = system('which cantata');
  223. w=['"' w(1:end-8)];
  224. end
  225. end
  226. [varargout{:}]=callKhoros([w 'vcast1" '],Inputs,narglist);