-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhereismax.pro
106 lines (95 loc) · 3.22 KB
/
whereismax.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
pro whereismax, image, x, y, maxv, mark=mark, silent=silent,single=single
;+
; NAME: whereismax
;
; PURPOSE:
; Given an array, returns location and value of max pixel
;
; INPUTS:
;
; pro Whereismax, image, x, y, maxv, mark=mark, silent=silent,single=single
;
;
; note that this will return a long integer if there is
; a unique max pixel, otherwise it will return an long array
; which may be a problem for some routines
;
; 10/31/94 MCL
;
; added mark feature, which will draw a cross at the max
; pixel on the current window
; 8/19/96 MCL
;
; uses a square instead of a circle for /mark
; 06/22/00 MCL
; Added "single" keyword to always return only one value. If multiple
; points have the same max, return only the first
; 2001-07-06 MDP
;
; 2003-03-04 MDP added /NaN keyword to max
; 2013-10-07 MDP Updated to use IDL's array_indices, which was added
; sometime since this was first written...
;-
;###########################################################################
;
; LICENSE
;
; This software is OSI Certified Open Source Software.
; OSI Certified is a certification mark of the Open Source Initiative.
;
; Copyright © 1994-2003 by Michael C. Liu & Marshall D. Perrin
;
; This software is provided "as-is", without any express or
; implied warranty. In no event will the authors be held liable
; for any damages arising from the use of this software.
;
; Permission is granted to anyone to use this software for any
; purpose, including commercial applications, and to alter it and
; redistribute it freely, subject to the following restrictions:
;
; 1. The origin of this software must not be misrepresented; you must
; not claim you wrote the original software. If you use this software
; in a product, an acknowledgment in the product documentation
; would be appreciated, but is not required.
;
; 2. Altered source versions must be plainly marked as such, and must
; not be misrepresented as being the original software.
;
; 3. This notice may not be removed or altered from any source distribution.
;
; For more information on Open Source Software, visit the Open Source
; web site: http://www.opensource.org.
;
;###########################################################################
if n_params() lt 1 then begin
message,'pro whereismax,image,(x),(y),(maxv),[mark],[silent],[single]'
endif
maxv = max(image,/NaN)
;whereis,image,where(image eq maxv),x,y
indices = array_indices(image, where(image eq maxv))
if (size(indices))[0] eq 1 then begin
x = indices[0]
y = indices[1]
endif else begin
x = indices[*,0]
y = indices[*,1]
endelse
if ((n_elements(x) eq 1) or keyword_set(single) ) then begin
if (n_elements(x) gt 1 and keyword_set(single) and ~(keyword_set(silent))) then $
message,"multiple maxes found; returning only the first",/info
x = x(0)
y = y(0)
endif
if keyword_set(silent) eq 0 then $
print,'max = ',strc(maxv),' at (',strc(fix(x)),',',strc(fix(y)),')'
sz = size(image)
rad = 0.05*avg(sz(1:2))
if keyword_set(mark) then begin
if (!d.window ne -1) then begin
oplot, [x], [y], sym = 10, ps = 1, color = 1
tvbox, 2*rad, x, y, /data, color = 1
;tvcircle, 40, x, y, /data, color = 1
endif else $
message, 'unable to mark b/c no windows available'
endif
end