PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kputimage.m

http://github.com/aludnam/MATLAB
Objective C | 359 lines | 356 code | 3 blank | 0 comment | 72 complexity | 92063f609b999008f0ec95580fa1c170 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kputimage 'Non-Interactive Image Display'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros putimage.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i 'Input File', required: 'File containing image'
  6. % InputFile: cmap 'Input Colormap ', optional: 'File containing alternate colormap filename'
  7. % InputFile: clip 'Input Clip Gate', optional: 'File containing clip mask'
  8. % Integer: xoffset 'Image X Offset', default: 0: 'Specifies the horizontal offset within the image display'
  9. % Integer: yoffset 'Image Y Offset', default: 0: 'Specifies the vertical offset within the image display'
  10. % String: redfn 'Define Map Function For Red ', default: 'M0': 'Provides an equation that specifies the red map column'
  11. % String: greenfn 'Define Map Function For Green ', default: 'M1': 'Provides an equation that specifies the green map column'
  12. % String: bluefn 'Define Map Function For Blue ', default: 'M2': 'Provides an equation that specifies the blue map column'
  13. % Integer: x 'X Placement', default: -1: 'X location for GUI autoplacement'
  14. % Integer: width 'Window Width ', default: 512: 'Window width'
  15. % Integer: y 'Y Placement', default: -1: 'Y location for GUI autoplacement'
  16. % Integer: height 'Window Height', default: 512: 'Window height'
  17. % Double: update 'Update time', default: 2: 'How often to check input file for modification'
  18. %
  19. % Example: kputimage({i, cmap, clip}, {'i','';'cmap','';'clip','';'xoffset',0;'yoffset',0;'redfn','M0';'greenfn','M1';'bluefn','M2';'x',-1;'width',512;'y',-1;'height',512;'update',2})
  20. %
  21. % Khoros helpfile follows below:
  22. %
  23. % PROGRAM
  24. % putimage - Non-Interactive Image Display
  25. %
  26. % DESCRIPTION
  27. % Putimage is a visualization program that displays image data. It
  28. % provides no mechanism for image interaction or modification; it simply
  29. % takes input data and displays it as an image on the screen.
  30. %
  31. % The input file containing the data to be displayed as an image is
  32. % monitored by default; the file is checked every 2 seconds for change,
  33. % and if it has been modified, the image display is updated accordingly.
  34. % The interval at which the input file is checked for modification may
  35. % be specified using the [-update] option. A value of 0 disables
  36. % checking.
  37. %
  38. % A clip mask may be used to dictate the portion of the data that is
  39. % displayed using the [-clip] argument. Clip masks are discussed in
  40. % Chapter 1 of this volume, Introduction to the Envision Toolbox Manual.
  41. %
  42. % An alternate input color map may be used to change the current color
  43. % map using the [-cmap] argument. Colormaps are discussed in Chapter 1
  44. % of this volume, Introduction to the Envision Toolbox Manual
  45. %
  46. % The horizontal and vertical offsets within the image display window
  47. % can be specified using the [-xoffset] and [-yoffset] arguments. These
  48. % offsets specify the upper left corner of the image that appears in the
  49. % display window. For small images which fit entirely within the image
  50. % display window, this will always be (0,0). However for large images
  51. % that must use a "pan icon" because the image will not fit entirely
  52. % within the image window, the x and y offsets may be any value ranging
  53. % from 0 to the width/height of the image display window.
  54. %
  55. % When displaying images of data type "complex", a complex
  56. % conversion value may be specified which dictates how complex data is
  57. % converted for display using the [-complex] argument. There are nine
  58. % different complex conversion types:
  59. %
  60. % "" 5
  61. % 1 - Real
  62. % 2 - Imaginary
  63. % 3 - Phase
  64. % 4 - Magnitude
  65. % 5 - Log Magnitude + 1
  66. % 6 - Log Magnitude
  67. % 7 - Log Magnitude Sqrt + 1
  68. % 8 - Log Magnitude Sqrt
  69. % 9 - Magnitude Sqrt
  70. %
  71. % When displaying image data, it is possible to specify how data is
  72. % normalized for display using the [-normaltype] argument. Before
  73. % images are displayed by the image object, normalization must be done
  74. % in order to ensure that the pixel values of the image fall within a
  75. % certain range. Normalization can be one or two types: local or
  76. % global. With "local" normalization, the normalization procedure
  77. % is performed locally using the maximum and minimum values of each of
  78. % the red, green, and blue map columns. For "global" normalization,
  79. % the normalization procedure is performed globally over all of the
  80. % three columns displayed as red, green, and blue.
  81. %
  82. % When data is normalized for display, it is possible to specify the algorithm
  83. % that defines how data is normalized by using the [-normalmethod] argument.
  84. % Normalization may be a simple stretch over the values that may be displayed
  85. % on a workstation, or any of three variations on a standard deviation
  86. % normalization may be used. For a simple normalization of values to within
  87. % displayable intensity bounds, set "Range: Maximum". Alternatively, images can
  88. % have contrast increased or reduced using one of the standard deviation
  89. % normalizations. The four different normalization methods are:
  90. %
  91. % "" 5
  92. % 1 - Range: Maximum
  93. % 2 - Range: +/-1 Standard Deviations
  94. % 3 - Range: +/-2 Standard Deviations
  95. % 4 - Range: +/-3 Standard Deviations
  96. %
  97. % When a colormap is present, it is possible to define which column (or
  98. % columns) in the color map is displayed as red, green, and blue using
  99. % the [-redcol], [-greencol], and [-bluecol] arguments. An image with a
  100. % simple colormap has three map columns associated with it, where the
  101. % pixels in the image are used to index into the map columns; the first
  102. % map column defines the red values, the second map column defines the
  103. % green values, and the third map column defines the blue values. In
  104. % this way, the color for each pixel in the image is defined. However,
  105. % for images that may have multiple map columns present, such as a
  106. % clustered image, it may be useful to view any of the map columns as
  107. % red, green, or blue.
  108. %
  109. %
  110. % Similar to specifying which map column(s) are displayed as red, green,
  111. % and blue, it is possible to define a function representing the colors
  112. % using the [-redfn], [-greenfn], and [-bluefn] arguments. With images
  113. % having colormaps made up of more than three columns, such as those
  114. % produced by clustering algorithms, it is often informative to be able
  115. % to apply a function to the values in those map columns in order to
  116. % define the values that will be displayed for each of the red, green, and
  117. % blue columns. For example, in an image having 6 map columns, you
  118. % might define the red intensity of pixel 10 as
  119. % \f(CW
  120. % (map column 2)[10]+ (map column 3)[10]/ map columns 4)[10].
  121. % "
  122. % In this case, the "Red Function"
  123. % may be set to the string defining the function to be applied in order
  124. % to produce the values that will be used as red. Functions must have
  125. % \fBonly" variable \fBM\fP, where \fBM\fP stands for "map column";
  126. % following each \fBM" must be a number \fBstarting at zero\fP and
  127. % ranging to \fBN-1", where \fBN\fP is the number of map columns
  128. % available in the image. For example, a valid function for red might
  129. % be:
  130. % \f(CW
  131. % (M2 - M3)/(M2 + M3) or (M0 + M1 + M2)/(M3 - M4).
  132. % "
  133. % Equation values follow the standard rules of precedence; evaluation
  134. % proceeds from left to right, and use of parentheses is fully
  135. % supported.
  136. % In a more simple use, the "Red Function" may also be the variable representing
  137. % the map column which is to be used to specify the red values of the pixels in
  138. % the image. For example, if you wanted the fourth map column to define the
  139. % red values of the pixels in the image, (remember that map column numbering
  140. % begins at 0), you could set "Red Function" to: M3. You can also set the
  141. % "Red Function" to a constant, if desired. For example, if you wanted the
  142. % red values of all the pixels in the image to be 200, you could set "Red
  143. % Function" to 200.
  144. % By default, the "Red Function" is set to \fBM0", or the first map
  145. % column, the "Green Function" is set to \fBM1", or the second map
  146. % column, and the "Blue Function" is set to \fBM2", or the third map
  147. % column. Thus, the defaults produce results that you would normally expect for
  148. % an image with a colormap where no function was being applied.
  149. %
  150. % By default, Putimage will share its colormap with all other
  151. % applications running at the same time; that is, it does not not use a
  152. % .I "private colormap",
  153. % but rather makes use of the
  154. % .I "default colormap".
  155. % It is possible to specify that Putimage allocate its own private
  156. % colormap or "grab" all available colors for its own use. This is done
  157. % using the [-priv] argument. When [-priv] is specified, moving the
  158. % mouse pointer into the display window will cause the display to have
  159. % its private colormap installed; moving the pointer out of the display
  160. % window will cause the private colormap to be de-installed. This
  161. % results in the "technoflashing" phenomenon characteristic of private
  162. % colormap installation.
  163. %
  164. % Color allocation can also be controlled and set to either
  165. % .I "read-only"
  166. % or
  167. % .I "read/write"
  168. % using the [-alloc] argument. When set to
  169. % .I "read-only",
  170. % once a color cell has been allocated, it can have its color set only
  171. % once; from then on, the color cell can be shared by multiple
  172. % applications, but not changed. If Putimage requires the color
  173. % displayed to change, it must re-allocate the color cell, forcing a
  174. % re-display of data. This can be an expensive procedure. In contrast,
  175. % after a
  176. % .I read/write
  177. % color cell is allocated, it can have its color changed at any time
  178. % without re-allocation; the data being displayed does not need to be
  179. % redisplayed, and the color update process is much more efficient.
  180. % However, the colors used in Putimage cannot be shared by other
  181. % applications.
  182. %
  183. % On creation, the image display window may be placed manually (the default
  184. % method), or placed automatically. For automatic placement of the image
  185. % window, specify the desired location in device (screen) coordinates using
  186. % the [-x] and [-y] arguments.
  187. %
  188. % While the image display window should be created with a default size that
  189. % is appropriate to display the data, a width and height for the window can
  190. % be specified explicitly using the [-width] and [-height] arguments. Note
  191. % that the interactive resizing of the image display window using the window
  192. % manager is currently NOT supported.
  193. %
  194. %
  195. %
  196. % EXAMPLES
  197. % % putimage -i image:ball
  198. % % putimage -i image:mandril
  199. %
  200. % "SEE ALSO"
  201. % putdata(1)
  202. %
  203. % RESTRICTIONS
  204. %
  205. % REFERENCES
  206. %
  207. % COPYRIGHT
  208. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  209. %
  210. function varargout = kputimage(varargin)
  211. if nargin ==0
  212. Inputs={};arglist={'',''};
  213. elseif nargin ==1
  214. Inputs=varargin{1};arglist={'',''};
  215. elseif nargin ==2
  216. Inputs=varargin{1}; arglist=varargin{2};
  217. else error('Usage: [out1,..] = kputimage(Inputs,arglist).');
  218. end
  219. if size(arglist,2)~=2
  220. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  221. end
  222. narglist={'i', '__input';'cmap', '__input';'clip', '__input';'xoffset', 0;'yoffset', 0;'redfn', 'M0';'greenfn', 'M1';'bluefn', 'M2';'x', -1;'width', 512;'y', -1;'height', 512;'update', 2};
  223. maxval={0,1,1,10000,10000,0,0,0,1000,1000,1000,1000,1};
  224. minval={0,1,1,0,0,0,0,0,-1,-1,-1,-1,1};
  225. istoggle=[0,1,1,1,1,1,1,1,1,1,1,1,1];
  226. was_set=istoggle * 0;
  227. paramtype={'InputFile','InputFile','InputFile','Integer','Integer','String','String','String','Integer','Integer','Integer','Integer','Double'};
  228. % identify the input arrays and assign them to the arguments as stated by the user
  229. if ~iscell(Inputs)
  230. Inputs = {Inputs};
  231. end
  232. NumReqOutputs=0; nextinput=1; nextoutput=1;
  233. for ii=1:size(arglist,1)
  234. wasmatched=0;
  235. for jj=1:size(narglist,1)
  236. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  237. wasmatched = 1;
  238. was_set(jj) = 1;
  239. if strcmp(narglist{jj,2}, '__input')
  240. if (nextinput > length(Inputs))
  241. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  242. end
  243. narglist{jj,2} = 'OK_in';
  244. nextinput = nextinput + 1;
  245. elseif strcmp(narglist{jj,2}, '__output')
  246. if (nextoutput > nargout)
  247. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  248. end
  249. if (isempty(arglist{ii,2}))
  250. narglist{jj,2} = 'OK_out';
  251. else
  252. narglist{jj,2} = arglist{ii,2};
  253. end
  254. nextoutput = nextoutput + 1;
  255. if (minval{jj} == 0)
  256. NumReqOutputs = NumReqOutputs - 1;
  257. end
  258. elseif isstr(arglist{ii,2})
  259. narglist{jj,2} = arglist{ii,2};
  260. else
  261. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  262. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  263. end
  264. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  265. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  266. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  267. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  268. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  269. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  270. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  271. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  272. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  273. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  274. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  275. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  276. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  277. end
  278. end
  279. end
  280. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  281. narglist{jj,2} = arglist{ii,2};
  282. end
  283. end
  284. end
  285. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  286. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  287. end
  288. end
  289. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  290. for jj=1:size(narglist,1)
  291. if strcmp(paramtype{jj}, 'Toggle')
  292. if (narglist{jj,2} ==0)
  293. narglist{jj,1} = '';
  294. end;
  295. narglist{jj,2} = '';
  296. end;
  297. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  298. narglist{jj,1} = '';
  299. narglist{jj,2} = '';
  300. end;
  301. if strcmp(narglist{jj,2}, '__input')
  302. if (minval{jj} == 0) % meaning this input is required
  303. if (nextinput > size(Inputs))
  304. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  305. else
  306. narglist{jj,2} = 'OK_in';
  307. nextinput = nextinput + 1;
  308. end
  309. else % this is an optional input
  310. if (nextinput <= length(Inputs))
  311. narglist{jj,2} = 'OK_in';
  312. nextinput = nextinput + 1;
  313. else
  314. narglist{jj,1} = '';
  315. narglist{jj,2} = '';
  316. end;
  317. end;
  318. else
  319. if strcmp(narglist{jj,2}, '__output')
  320. if (minval{jj} == 0) % this is a required output
  321. if (nextoutput > nargout & nargout > 1)
  322. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  323. else
  324. narglist{jj,2} = 'OK_out';
  325. nextoutput = nextoutput + 1;
  326. NumReqOutputs = NumReqOutputs-1;
  327. end
  328. else % this is an optional output
  329. if (nargout - nextoutput >= NumReqOutputs)
  330. narglist{jj,2} = 'OK_out';
  331. nextoutput = nextoutput + 1;
  332. else
  333. narglist{jj,1} = '';
  334. narglist{jj,2} = '';
  335. end;
  336. end
  337. end
  338. end
  339. end
  340. if nargout
  341. varargout = cell(1,nargout);
  342. else
  343. varargout = cell(0);
  344. end
  345. global KhorosRoot
  346. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  347. w=['"' KhorosRoot];
  348. else
  349. if ispc
  350. w='"C:\Program Files\dip\khorosBin\';
  351. else
  352. [s,w] = system('which cantata');
  353. w=['"' w(1:end-8)];
  354. end
  355. end
  356. callKhoros([w 'putdata" -image'],Inputs,narglist);