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

/matlab_tools/Converted/kvsmoothseg.m

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