PageRenderTime 39ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/matlab_tools/Converted/kcxretouch.m

http://github.com/aludnam/MATLAB
Objective C | 195 lines | 192 code | 3 blank | 0 comment | 58 complexity | 73830e9ef5178c98591bc1b0828fa5a7 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kcxretouch 'Interactively retouch (paint) a classified image'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros cxretouch.pane file
  3. %
  4. % Parameters:
  5. % InputFile: iclass 'Input Classified Image', required: 'input classified image'
  6. % InputFile: icsf 'Input Class Specification File', required: 'input class specification file'
  7. % OutputFile: o 'Output Retouched Image', required: 'Resulting output data object'
  8. %
  9. % Example: o = kcxretouch({iclass, icsf}, {'iclass','';'icsf','';'o',''})
  10. %
  11. % Khoros helpfile follows below:
  12. %
  13. % PROGRAM
  14. % cxretouch - Interactively retouch (paint) a classified image
  15. %
  16. % DESCRIPTION
  17. % Interactive Retouch (cxretouch xvroutine) allows the user to interactively retouch classification results. It is intended to be used for removal of small non-classified areas and region-constrained mode filtering.
  18. % This program is \fBnot\fp a full-featured graphics editor - if that's what you want I'd suggest you to export the classification results to a ppm file with "kformats" and use xpaint or a similar program. Alternatively you can use the netpbm package or xv program to convert the ppm output to gif, tiff, bmp, etc. formats which can be edited with most Windows graphics packages.
  19. % The advantages of using this program is that it will work on the native data of the classification results, i.e. preserving the map, mask and value data used by the Khoros Polymorphic Data Services to represent classified data.
  20. % This xvroutine expects as inputs the classified result [-iclass] and the Class Specification File for that classification task [-icsf], which will be used to get the classes' labels and colors. Its output [-o] will be the edited result. The input classified result \fBmust" have a map segment, i.e. it should be the output of a cthematicmap operator.
  21. % The xvroutine will have a workspace for display of the classified image, zoom over the pointer position, a selector for the classes present in the Class Specification File (plus the "rejected" class), a button that will allow the present class to be selected from the classified image, seven buttons for area size selection (1x1, 3x3, 5x5, 9x9, 13x13, 25x25, 49x49), a mode selector (see below), buttons for polygon region selection (rectangle, ellipse, polyline, freehand).
  22. % Editing can be done in three modes:
  23. % 1- Paint mode: the user selects a class from the class selector, a square region button or a polygon selection button and paints by clicking on the regions in the image.
  24. % 2- Mode filtering mode: the user selects a region size and click over it, the program will apply a mode filter over the region. The mode filter mode (no, it is not redundant) can be selected in the Mode menu button. The mode filter will eliminate small misclassified regions.
  25. % 3- Masking mode - the same as paint mode except that it will mask the "painted" regions as if they were rejected by the classifier. This more can be activated by choosing the Rejected class in the Class selector or by choosing the mode Reject (mask) in the mode selector.
  26. % The xvroutine also have primitive (1-level) undo and redo functions, with the respective buttons.
  27. %
  28. %
  29. %
  30. % EXAMPLES
  31. % All examples for the Classify toolbox are listed on the Classify Toolbox Manual. For an example of this xvroutine, please see the Classify:workspaces:MINDIST-Classify example workspace.
  32. %
  33. % "SEE ALSO"
  34. % cthematicmap, csimplemode, Class Specification File format in the Classify Toolbox Manual.
  35. %
  36. % RESTRICTIONS
  37. % Expect the parameter [-icsf] to point to a valid Class Specification file, and the parameters [-iclass] to be a result of classification with one of the classifiers in this toolbox, preferably with a map applied with cthematicmap.
  38. % Due to a refresh bug, when you select the paint or mode filter over large regions the program will take some time to refresh the window, if the window loses the focus it will appear black temporarily. This does \fBnot" have any effect on the image, and after the paint/mode processing it will return to the normal.
  39. %
  40. % REFERENCES
  41. % All references for the Classify toolbox are listed on the Classify Toolbox Manual.
  42. %
  43. % COPYRIGHT
  44. % Copyright (C) 1997 Rafael Santos. Khoros (C) Khoral Research, Inc.
  45. %
  46. function varargout = kcxretouch(varargin)
  47. if nargin ==0
  48. Inputs={};arglist={'',''};
  49. elseif nargin ==1
  50. Inputs=varargin{1};arglist={'',''};
  51. elseif nargin ==2
  52. Inputs=varargin{1}; arglist=varargin{2};
  53. else error('Usage: [out1,..] = kcxretouch(Inputs,arglist).');
  54. end
  55. if size(arglist,2)~=2
  56. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  57. end
  58. narglist={'iclass', '__input';'icsf', '__input';'o', '__output'};
  59. maxval={0,0,0};
  60. minval={0,0,0};
  61. istoggle=[0,0,0];
  62. was_set=istoggle * 0;
  63. paramtype={'InputFile','InputFile','OutputFile'};
  64. % identify the input arrays and assign them to the arguments as stated by the user
  65. if ~iscell(Inputs)
  66. Inputs = {Inputs};
  67. end
  68. NumReqOutputs=1; nextinput=1; nextoutput=1;
  69. for ii=1:size(arglist,1)
  70. wasmatched=0;
  71. for jj=1:size(narglist,1)
  72. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  73. wasmatched = 1;
  74. was_set(jj) = 1;
  75. if strcmp(narglist{jj,2}, '__input')
  76. if (nextinput > length(Inputs))
  77. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  78. end
  79. narglist{jj,2} = 'OK_in';
  80. nextinput = nextinput + 1;
  81. elseif strcmp(narglist{jj,2}, '__output')
  82. if (nextoutput > nargout)
  83. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  84. end
  85. if (isempty(arglist{ii,2}))
  86. narglist{jj,2} = 'OK_out';
  87. else
  88. narglist{jj,2} = arglist{ii,2};
  89. end
  90. nextoutput = nextoutput + 1;
  91. if (minval{jj} == 0)
  92. NumReqOutputs = NumReqOutputs - 1;
  93. end
  94. elseif isstr(arglist{ii,2})
  95. narglist{jj,2} = arglist{ii,2};
  96. else
  97. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  98. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  99. end
  100. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  101. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  102. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  103. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  104. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  105. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  106. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  107. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  108. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  109. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  110. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  111. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  112. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  113. end
  114. end
  115. end
  116. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  117. narglist{jj,2} = arglist{ii,2};
  118. end
  119. end
  120. end
  121. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  122. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  123. end
  124. end
  125. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  126. for jj=1:size(narglist,1)
  127. if strcmp(paramtype{jj}, 'Toggle')
  128. if (narglist{jj,2} ==0)
  129. narglist{jj,1} = '';
  130. end;
  131. narglist{jj,2} = '';
  132. end;
  133. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  134. narglist{jj,1} = '';
  135. narglist{jj,2} = '';
  136. end;
  137. if strcmp(narglist{jj,2}, '__input')
  138. if (minval{jj} == 0) % meaning this input is required
  139. if (nextinput > size(Inputs))
  140. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  141. else
  142. narglist{jj,2} = 'OK_in';
  143. nextinput = nextinput + 1;
  144. end
  145. else % this is an optional input
  146. if (nextinput <= length(Inputs))
  147. narglist{jj,2} = 'OK_in';
  148. nextinput = nextinput + 1;
  149. else
  150. narglist{jj,1} = '';
  151. narglist{jj,2} = '';
  152. end;
  153. end;
  154. else
  155. if strcmp(narglist{jj,2}, '__output')
  156. if (minval{jj} == 0) % this is a required output
  157. if (nextoutput > nargout & nargout > 1)
  158. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  159. else
  160. narglist{jj,2} = 'OK_out';
  161. nextoutput = nextoutput + 1;
  162. NumReqOutputs = NumReqOutputs-1;
  163. end
  164. else % this is an optional output
  165. if (nargout - nextoutput >= NumReqOutputs)
  166. narglist{jj,2} = 'OK_out';
  167. nextoutput = nextoutput + 1;
  168. else
  169. narglist{jj,1} = '';
  170. narglist{jj,2} = '';
  171. end;
  172. end
  173. end
  174. end
  175. end
  176. if nargout
  177. varargout = cell(1,nargout);
  178. else
  179. varargout = cell(1,1);
  180. end
  181. global KhorosRoot
  182. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  183. w=['"' KhorosRoot];
  184. else
  185. if ispc
  186. w='"C:\Program Files\dip\khorosBin\';
  187. else
  188. [s,w] = system('which cantata');
  189. w=['"' w(1:end-8)];
  190. end
  191. end
  192. [varargout{:}]=callKhoros([w 'cxretouch" '],Inputs,narglist);