-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan2d_roi.pro
1616 lines (1401 loc) · 50.5 KB
/
scan2d_roi.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;*************************************************************************
; Copyright (c) 2002 The University of Chicago, as Operator of Argonne
; National Laboratory.
; Copyright (c) 2002 The Regents of the University of California, as
; Operator of Los Alamos National Laboratory.
; This file is distributed subject to a Software License Agreement found
; in the file LICENSE that is included with this distribution.
;*************************************************************************
@PS_open.pro
PRO defroi_congrid,statistic_2dids,arr,xverts,yverts,xs=xs,ys=ys,x0=x0,y0=y0
; define a polygon region
;
im = *statistic_2dids.im0
wset,statistic_2dids.wid
xl = statistic_2dids.margin_l
yl = statistic_2dids.margin_b
xw = statistic_2dids.xsize
yw = statistic_2dids.ysize
if keyword_set(x0) then xl = x0
if keyword_set(y0) then yl = y0
if keyword_set(xs) then xw = xs
if keyword_set(ys) then yw = ys
sz = size(*statistic_2dids.im0)
width = statistic_2dids.width ; sz(1)
height = statistic_2dids.height ; sz(2)
zoom = [xw/sz(1),yw/sz(2)]
tvscl,congrid(im,xw,yw),xl,yl
r = defroi(xw+1,yw+1,xv,yv,x0=xl,y0=yl)
xverts = xv / statistic_2dids.factor(0)
yverts = yv / statistic_2dids.factor(1)
xverts = fix(xverts+.5)
yverts = fix(yverts+.5)
arr = polyfillv(xverts,yverts,statistic_2dids.width,statistic_2dids.height)
if n_elements(arr) eq 1 then begin
res = dialog_message('At least two elements must be picked for polygon region defined !!',/Error)
return
endif else begin
res = dialog_message('Do you want to over-write the old polygon ROI ?',/question)
if res eq 'No' then return
end
statistic_2dids.roi_nelem = n_elements(arr)
statistic_2dids.roi_elist = 0
statistic_2dids.roi_elist = arr
; statistic_2dWritePolyROI,statistic_2dids,xverts,yverts,r_index
statistic_2dWritePolyROI,statistic_2dids,xv,yv,arr
END
PRO statistic_2dPlot, statistic_2dids
wset,statistic_2dids.wid
erase
im = *statistic_2dids.im0
; if lower level threshhold value is given
if statistic_2dids.back eq 1 then begin
; im = im > statistic_2dids.backave
tv,bytscl(congrid(im,300,300),min=statistic_2dids.backave, $
max=statistic_2dids.backave2), $
statistic_2dids.margin_l,statistic_2dids.margin_b, $
xsize=statistic_2dids.xsize,ysize=statistic_2dids.ysize
endif else $
; whole image region
tvscl,congrid(im,300,300), $
statistic_2dids.margin_l,statistic_2dids.margin_b, $
xsize=statistic_2dids.xsize,ysize=statistic_2dids.ysize
; if const image is found
if statistic_2dids.max eq statistic_2dids.min then begin
tv,congrid(im*(!d.table_size-1),300,300), $
statistic_2dids.margin_l,statistic_2dids.margin_b, $
xsize=statistic_2dids.xsize,ysize=statistic_2dids.ysize
end
p1 = [float(statistic_2dids.margin_l)/ !d.x_size, $
float(statistic_2dids.margin_b)/ !d.y_size, $
float(!d.x_size - statistic_2dids.margin_r)/ !d.x_size, $
float(!d.y_size - statistic_2dids.margin_t)/ !d.y_size $
]
width = n_elements(statistic_2dids.x)
height = n_elements(statistic_2dids.y)
xrange = [0,width]
yrange = [0,height]
if statistic_2dids.versus eq 1 then begin
xrange = [statistic_2dids.x(0),statistic_2dids.x(width-1)]
yrange = [statistic_2dids.y(0),statistic_2dids.y(height-1)]
end
plot,/noerase,/nodata,pos=p1, [-1.,-1.], $
title=' ',$
xrange=xrange,yrange=yrange, xstyle=1,ystyle=1
xyouts,!d.x_ch_size,!d.y_size -!d.y_ch_size,statistic_2dids.header(1),/device
if statistic_2dids.back eq 0 then scan2d_ROI_LMB ,statistic_2dids
if statistic_2dids.back eq 1 then $
statistic_2dRange,statistic_2dids,im,statistic_2dids.backave,statistic_2dids.backave2
if statistic_2dids.back eq 2 then $
statistic_2dPickedPolygon,statistic_2dids,im
statistic_2dids.cross = 0
END
PRO statistic_2dReadPolyROI,statistic_2dids,xverts,yverts,xv,yv,arr,r_index
xdr_open,unit,statistic_2dids.picked
xdr_read,unit,xv
xdr_read,unit,yv
xdr_close,unit
statistic_2dids.roi_elist = 0
xverts = fix(xv / statistic_2dids.factor(0)+.5)
yverts = fix(yv / statistic_2dids.factor(1)+.5)
arr = polyfillv(xverts,yverts,statistic_2dids.width,statistic_2dids.height)
statistic_2dids.roi_nelem = n_elements(arr)
statistic_2dids.roi_elist = arr
END
PRO statistic_2dWritePolyROI,statistic_2dids,xverts,yverts,r_index
xdr_open,unit,statistic_2dids.picked,/write
xdr_write,unit,xverts
xdr_write,unit,yverts
xdr_close,unit
END
PRO statistic_2dPickedPolygon,statistic_2dids,im
;
found = findfile(statistic_2dids.picked)
if found(0) eq '' then return
; xverts,yverts in data index
; xv,yv in pixels
statistic_2dReadPolyROI,statistic_2dids,xverts,yverts,xv,yv,arr,r_index
device,get_graphics_function=oldGraphFunc
device,set_graphics_function=6
polyfill,xv+statistic_2dids.margin_l, $
yv+statistic_2dids.margin_b, $
/dev,color = !d.table_size-1,/noclip
device,set_graphics_function=oldGraphFunc
if n_elements(arr) eq 1 then begin
res = dialog_message('The polygon ROI not suitable for this image',/Info)
return
end
temp_ind = arr
sz = size(im)
width = sz(1)
height = sz(2)
nelem = n_elements(temp_ind)
case sz(3) of
1: temp = make_array(nelem,/byte)
2: temp = make_array(nelem,/int)
3: temp = make_array(nelem,/long)
4: temp = make_array(nelem,/float)
5: temp = make_array(nelem,/double)
else:
endcase
statistic_2dids.roi_nelem = nelem
for ij=0L,nelem-1 do begin
j = temp_ind(ij) / width
i = temp_ind(ij) MOD width
temp(ij) = im(i,j)
end
result = moment(temp,mdev=mdev,sdev=sdev)
temp_min = min(temp,jmin)
temp_max = max(temp,jmax)
jmin = temp_ind(jmin)
jmax = temp_ind(jmax)
min_i = jmin MOD width
min_j = jmin / width
max_i = jmax MOD width
max_j = jmax / width
scan2d_ROI_field,statistic_2dids,result(0),sdev,temp_min,temp_max,min_i,min_j,max_i,max_j
statistic_2dids.roi_total = total(temp)
statistic_2dids.roi_nelem = n_elements(temp)
statistic_2dids.roi_max = temp_max
statistic_2dids.roi_min = temp_min
statistic_2dids.roi_ave = result(0)
statistic_2dids.roi_dev = sdev
; update ROI label
; region defined by defroi routine
st='ROI: defined by PolyROI '+ $
', Nelem='+strtrim(statistic_2dids.roi_nelem,2)+ $
', Total='+strtrim(statistic_2dids.roi_total,2)
WIDGET_CONTROL,statistic_2dids.roiid,SET_VALUE=st
END
PRO statistic_2dWriteFilter,statistic_2dids,lower_b,upper_b
im = *statistic_2dids.im0
bine = (im ge lower_b) and (im le upper_b)
len = strpos(statistic_2dids.file,"_roi")
if len ge 0 then class = strmid(statistic_2dids.file,0,len)
xdr_open,unit,class+'_roi.pickfltr',/write
xdr_write,unit,bine
xdr_write,unit,lower_b
xdr_write,unit,upper_b
xdr_close,unit
END
PRO statistic_2dReadFilter,statistic_2dids,lower_b,upper_b
len = strpos(statistic_2dids.file,"_roi")
if len ge 0 then class = strmid(statistic_2dids.file,0,len)
xdr_open,unit,class+'_roi.pickfltr'
xdr_read,unit,bine
xdr_read,unit,lower_b
xdr_read,unit,upper_b
xdr_close,unit
;print,lower_b,upper_b
;print,bine
END
PRO statistic_2dRange,statistic_2dids,im,lower_b,upper_b
;
; extract the elements fall in between the selected range
; statistic_2dids.backave < < statistic_2dids.backave2
;
sz = size(im)
width = sz(1)
height = sz(2)
xrange = [0,width-1]
yrange = [0,height-1]
bine = (im ge lower_b) and (im le upper_b)
nelem = long(total(bine))
if nelem gt 1 then begin
temp = make_array(nelem)
temp_ind = make_array(nelem,/long)
ij = 0L
for j=0,height-1 do begin
for i=0,width-1 do begin
if im(i,j) ge lower_b and im(i,j) le upper_b then begin
temp(ij) = im(i,j)
temp_ind(ij) = i+ 1L*j*width
ij=ij+1
end
end
end
statistic_2dids.roi_nelem = nelem
statistic_2dids.roi_elist = 0
statistic_2dids.roi_elist = temp_ind
endif else begin
res = dialog_message('ROI too small, at least 2 elements has to be selected',/Info)
temp=im * 0
return
end
if statistic_2dids.back eq 0 then temp = im
result = moment(temp,mdev=mdev,sdev=sdev)
temp_min = min(temp,jmin)
temp_max = max(temp,jmax)
if statistic_2dids.back eq 1 then begin
jmin = temp_ind(jmin)
jmax = temp_ind(jmax)
end
min_i = jmin MOD width
min_j = jmin /width
max_i = jmax MOD width
max_j = jmax / width
scan2d_ROI_field,statistic_2dids,result(0),sdev,temp_min,temp_max,min_i,min_j,max_i,max_j
statistic_2dids.roi_total = total(temp)
statistic_2dids.roi_nelem = n_elements(temp)
statistic_2dids.roi_max = temp_max
statistic_2dids.roi_min = temp_min
statistic_2dids.roi_ave = result(0)
statistic_2dids.roi_dev = sdev
; update ROI label
; if backgrund threshold value is given
st='ROI: IM['+ strtrim(xrange(0),2) +':'+ strtrim(xrange(1),2)+', '+ $
strtrim(yrange(0),2)+':'+ strtrim(yrange(1),2)+']'+ $
', Nelem='+strtrim(statistic_2dids.roi_nelem,2)+ $
', Total='+strtrim(statistic_2dids.roi_total,2)
WIDGET_CONTROL,statistic_2dids.roiid,SET_VALUE=st
END
PRO boxregion,statistic_2dids,Event
; device,get_graphics_function=gmode
; if gmode eq 6 then begin
; xbox = [statistic_2dids.x1,statistic_2dids.x2,statistic_2dids.x2]
; ybox = [statistic_2dids.y1,statistic_2dids.y1,statistic_2dids.y2]
; xbox = xbox + statistic_2dids.margin_l
; ybox = ybox + statistic_2dids.margin_b
; plots,xbox,ybox,/device,thick=2
; xbox = [statistic_2dids.x1,statistic_2dids.x1,statistic_2dids.x2]
; ybox = [statistic_2dids.y1,statistic_2dids.y2,statistic_2dids.y2]
; xbox = xbox + statistic_2dids.margin_l
; ybox = ybox + statistic_2dids.margin_b
; plots,xbox,ybox,/device,thick=2
; endif else device,set_graphics_function=6
st=['You are in the define rectangular ROI mode', $
'Press and move LMB to select the ROI', $
'Release and move LMB to show the ROI box']
WIDGET_CONTROL,statistic_2dids.message,SET_VALUE=st
wset,statistic_2dids.wid
if !d.n_colors gt !d.table_size then begin
tvscl,congrid(statistic_2dids.im,300,300), $
statistic_2dids.margin_l,statistic_2dids.margin_b, $
xsize=statistic_2dids.xsize,ysize=statistic_2dids.ysize
endif else $
tv,statistic_2dids.pixmap,statistic_2dids.margin_l,statistic_2dids.margin_b
device,set_graphics_function=6
cursor,x1,y1,/device,/change ; /nowait
while(!err eq 1) do begin
cursor,x2,y2,/device,/change,/nowait ; draw continuously
plots,[x1,x2,x2],[y1,y1,y2],/device,thick=2
plots,[x1,x1,x2],[y1,y2,y2],/device,thick=2
plots,[x1,x2,x2],[y1,y1,y2],/device,thick=2
plots,[x1,x1,x2],[y1,y2,y2],/device,thick=2
endwhile
if n_elements(x2) eq 0 then begin
device,set_graphics_function=3
return
end
statistic_2dids.x1 = x1 - statistic_2dids.margin_l
statistic_2dids.x2 = x2 - statistic_2dids.margin_l
if x2 lt x1 then begin
statistic_2dids.x1 = x2 - statistic_2dids.margin_l
statistic_2dids.x2 = x1 - statistic_2dids.margin_l
end
statistic_2dids.y1 = y1 - statistic_2dids.margin_b
statistic_2dids.y2 = y2 - statistic_2dids.margin_b
if y2 lt y1 then begin
statistic_2dids.y1 = y2 - statistic_2dids.margin_b
statistic_2dids.y2 = y1 - statistic_2dids.margin_b
end
plots,[x1,x2,x2],[y1,y1,y2],/device,thick=2
plots,[x1,x1,x2],[y1,y2,y2],/device,thick=2
device,set_graphics_function=3
WIDGET_CONTROL,statistic_2dids.message,SET_VALUE="**Press MMB to Query Pixel Values**"
END
PRO scan2d_ROI_MMB,statistic_2dids
wset,statistic_2dids.wid
cursor,px2,py2,0,/device
device,set_graphics_function=6
if statistic_2dids.cross then begin
plots,[statistic_2dids.cursor_x,statistic_2dids.cursor_x], $
[statistic_2dids.margin_b,!d.y_size-statistic_2dids.margin_t],/device
plots,[statistic_2dids.margin_l,!d.x_size-statistic_2dids.margin_r], $
[statistic_2dids.cursor_y,statistic_2dids.cursor_y],/device
end
statistic_2dids.cross = 1
statistic_2dids.cursor_x=px2
statistic_2dids.cursor_y=py2
plots,[px2,px2],[statistic_2dids.margin_b,!d.y_size-statistic_2dids.margin_t],/device
plots,[statistic_2dids.margin_l,!d.x_size-statistic_2dids.margin_r],[py2,py2],/device
device,set_graphics_function=3
px2 = px2-statistic_2dids.margin_l
py2 = py2-statistic_2dids.margin_b
x2 = fix(px2/statistic_2dids.factor[0])
y2 = fix(py2/statistic_2dids.factor[1]) ;+.5)
if x2 ge statistic_2dids.width or $
y2 ge statistic_2dids.height then begin
res = dialog_message('Out of image area!',/error)
return
end
if statistic_2dids.versus eq 1 then begin
st = 'CURSOR: X='+strtrim(statistic_2dids.x(x2),2)+', Y=' $
+strtrim(statistic_2dids.y(y2),2)+','
endif else begin
st = 'CURSOR: Ix='+strtrim(x2,2)+', Jy='+strtrim((y2),2)+','
end
im0 = *statistic_2dids.im0
stv= ' Pixel Value ='+strtrim(im0(x2,y2),2)
WIDGET_CONTROL,statistic_2dids.cursor,SET_VALUE=st
WIDGET_CONTROL,statistic_2dids.cursorv,SET_VALUE=stv
if statistic_2dids.debug then print,'cursor:i,j=',px2,py2,x2,y2
statistic_2dids.cursor_i = x2
statistic_2dids.cursor_j = y2
END
PRO scan2d_ROI_LMB,statistic_2dids
xbox = [statistic_2dids.x1,statistic_2dids.x2,statistic_2dids.x2]
ybox = [statistic_2dids.y1,statistic_2dids.y1,statistic_2dids.y2]
xbox = xbox + statistic_2dids.margin_l
ybox = ybox + statistic_2dids.margin_b
plots,xbox,ybox,/device,thick=2
xbox = [statistic_2dids.x1,statistic_2dids.x1,statistic_2dids.x2]
ybox = [statistic_2dids.y1,statistic_2dids.y2,statistic_2dids.y2]
xbox = xbox + statistic_2dids.margin_l
ybox = ybox + statistic_2dids.margin_b
plots,xbox,ybox,/device,thick=2
statistic_2dids.xrange[0] = fix(statistic_2dids.x1/statistic_2dids.factor[0])
statistic_2dids.yrange[0] = fix(statistic_2dids.y1/statistic_2dids.factor[1])
statistic_2dids.xrange[1] = fix(statistic_2dids.x2/statistic_2dids.factor[0])
statistic_2dids.yrange[1] = fix(statistic_2dids.y2/statistic_2dids.factor[1]) ;+.5)
if statistic_2dids.xrange[1] ge n_elements(statistic_2dids.x) then statistic_2dids.xrange[1] = n_elements(statistic_2dids.x) - 1
if statistic_2dids.yrange[1] ge n_elements(statistic_2dids.y) then statistic_2dids.yrange[1] = n_elements(statistic_2dids.y) - 1
if statistic_2dids.debug then begin
print,'x1,y1',statistic_2dids.x1,statistic_2dids.y1
print,'x2,y2',statistic_2dids.x2,statistic_2dids.y2
print,'factor',statistic_2dids.factor
print,'xrange',statistic_2dids.xrange
print,'yrange',statistic_2dids.yrange
end
xrange = statistic_2dids.xrange
if xrange(1) lt xrange(0) then begin
statistic_2dids.xrange(0) = xrange(1)
statistic_2dids.xrange(1) = xrange(0)
end
yrange = statistic_2dids.yrange
if yrange(1) lt yrange(0) then begin
statistic_2dids.yrange(0) = yrange(1)
statistic_2dids.yrange(1) = yrange(0)
end
im0 = *statistic_2dids.im0
sz = size(im0)
if sz(0) eq 2 then begin
if statistic_2dids.xrange(1) ge sz(1) then statistic_2dids.xrange(1) = sz(1)-1
if statistic_2dids.yrange(1) ge sz(2) then statistic_2dids.yrange(1) = sz(2)-1
end
temp2 = im0(statistic_2dids.xrange(0):statistic_2dids.xrange(1),$
statistic_2dids.yrange(0):statistic_2dids.yrange(1))
if n_elements(temp2) lt 2 then begin
res = dialog_message('ROI is too small! Try again.',/Error)
return
end
dj = statistic_2dids.yrange(1) - statistic_2dids.yrange(0) + 1
di = statistic_2dids.xrange(1) - statistic_2dids.xrange(0) + 1
for j=0L,dj-1 do begin
ij = (j+statistic_2dids.yrange(0)) * statistic_2dids.width $
+ statistic_2dids.xrange(0)
ll = indgen(di) + ij
if n_elements(elist) eq 0 then elist = ll else $
elist = [elist,ll]
i = di+statistic_2dids.xrange(0)
end
statistic_2dids.roi_nelem = n_elements(elist)
statistic_2dids.roi_elist = 0
statistic_2dids.roi_elist = elist
result = moment(temp2,mdev=mdev,sdev=sdev)
temp_max = max(temp2,jmax)
max_i = statistic_2dids.xrange[0] + $
jmax MOD (statistic_2dids.xrange[1]-statistic_2dids.xrange[0]+1)
max_j = statistic_2dids.yrange[0] + $
jmax / (statistic_2dids.xrange[1]-statistic_2dids.xrange[0]+1)
temp_min = min(temp2,jmin)
min_i = statistic_2dids.xrange[0] + $
jmin MOD (statistic_2dids.xrange[1]-statistic_2dids.xrange[0]+1)
min_j = statistic_2dids.yrange[0] + $
jmin / (statistic_2dids.xrange[1]-statistic_2dids.xrange[0]+1)
statistic_2dids.min_i = min_i
statistic_2dids.min_j = min_j
statistic_2dids.max_i = max_i
statistic_2dids.max_j = max_j
statistic_2dids.roi_total = total(temp2)
statistic_2dids.roi_nelem = n_elements(temp2)
statistic_2dids.roi_max = temp_max
statistic_2dids.roi_min = temp_min
statistic_2dids.roi_ave = result(0)
statistic_2dids.roi_dev = sdev
scan2d_ROI_field,statistic_2dids,result(0),sdev,temp_min,temp_max,min_i,min_j,max_i,max_j
; ROI
st='ROI: IM['+strtrim(statistic_2dids.xrange(0),2)+':'+ $
strtrim(statistic_2dids.xrange(1),2)+', '+ $
strtrim(statistic_2dids.yrange(0),2)+':'+ $
strtrim(statistic_2dids.yrange(1),2)+']'+ $
', Nelem='+strtrim(statistic_2dids.roi_nelem,2)+ $
', Total='+strtrim(statistic_2dids.roi_total,2)
WIDGET_CONTROL,statistic_2dids.roiid,SET_VALUE=st
END
PRO scan2d_ROI_field,statistic_2dids,ave,dev,tmin,tmax,min_i,min_j,max_i,max_j
WIDGET_CONTROL,statistic_2dids.aveid,SET_VALUE=ave
WIDGET_CONTROL,statistic_2dids.devid,SET_VALUE=dev
WIDGET_CONTROL,statistic_2dids.minid,SET_VALUE=tmin
WIDGET_CONTROL,statistic_2dids.maxid,SET_VALUE=tmax
if statistic_2dids.versus eq 0 then begin
WIDGET_CONTROL,statistic_2dids.minxid,SET_VALUE=min_i
WIDGET_CONTROL,statistic_2dids.minyid,SET_VALUE=min_j
WIDGET_CONTROL,statistic_2dids.maxxid,SET_VALUE=max_i
WIDGET_CONTROL,statistic_2dids.maxyid,SET_VALUE=max_j
endif else begin
WIDGET_CONTROL,statistic_2dids.minxid,SET_VALUE=statistic_2dids.x(min_i)
WIDGET_CONTROL,statistic_2dids.minyid,SET_VALUE=statistic_2dids.y(min_j)
WIDGET_CONTROL,statistic_2dids.maxxid,SET_VALUE=statistic_2dids.x(max_i)
WIDGET_CONTROL,statistic_2dids.maxyid,SET_VALUE=statistic_2dids.y(max_j)
end
END
PRO PDMENU13_Event,statistic_2dids, Event
CASE Event.Value OF
'ROIFile.New...': BEGIN
filter='*roi.xdr*'
if statistic_2dids.back eq 2 then filter='*roi*poly*'
f = dialog_pickfile(path=statistic_2dids.roipath,filter=filter, $
title='New ROI File',get_path=p,/WRITE)
found = findfile(f)
if found(0) ne '' then begin
res=dialog_message('File already exists!!',/Error)
return
end
if strtrim(f,2) ne '' then begin
WIDGET_CONTROL,statistic_2dids.fileid,SET_VALUE=f
res = strpos(f,'.poly')
if res gt 0 then f= strmid(f,0,res)
statistic_2dids.file = f
statistic_2dids.roipath = p
statistic_2dids.picked = f+'.poly'
end
END
'ROIFile.Open...': BEGIN
filter='*roi.xdr*'
if statistic_2dids.back eq 2 then filter='*roi*poly*'
f = dialog_pickfile( path=statistic_2dids.roipath,filter=filter, $
title='Pick ROI File',/MUST_EXIST,get_path=p,/WRITE)
if strtrim(f,2) ne '' then begin
WIDGET_CONTROL,statistic_2dids.fileid,SET_VALUE=f
res = strpos(f,'.poly')
if res gt 0 then f= strmid(f,0,res)
statistic_2dids.file = f
statistic_2dids.roipath = p
statistic_2dids.picked = f+'.poly'
scan2d_ROI_readroi,statistic_2dids
end
END
ENDCASE
END
PRO ROI2D_PDMENU3_Event,statistic_2dids, Event
CASE Event.Value OF
'RptFile.New...': BEGIN
PRINT, 'Event for File.New...'
f = dialog_pickfile( path=statistic_2dids.rptpath,filter='*roi.rpt*', $
get_path=p,title='ROI Report.New...',/WRITE)
found = findfile(f)
if found(0) ne '' then begin
res=dialog_message('File already exists!!',/Error)
return
end
if strtrim(f,2) ne '' then begin
WIDGET_CONTROL,statistic_2dids.rptid,SET_VALUE=f
statistic_2dids.rpt = f
statistic_2dids.rptpath = p
end
END
'RptFile.Open...': BEGIN
PRINT, 'Event for File.Open...'
f = dialog_pickfile(path=statistic_2dids.rptpath,filter='*roi.rpt*', $
get_path=p,title='ROI Report.Open...',/MUST_EXIST,/WRITE)
if strtrim(f,2) ne '' then begin
WIDGET_CONTROL,statistic_2dids.rptid,SET_VALUE=f
statistic_2dids.rpt = f
statistic_2dids.rptpath = p
end
END
ENDCASE
END
PRO scan2d_ROI_default, statistic_2dids
statistic_2dids.x1=0
statistic_2dids.y1=0
statistic_2dids.x2=300
statistic_2dids.y2=300
statistic_2dPlot,statistic_2dids
statistic_2dids.refresh = 1
END
PRO scan2d_ROI_Event, Event
WIDGET_CONTROL,Event.Top,GET_UVALUE=statistic_2dids
WIDGET_CONTROL,Event.Id,GET_UVALUE=Ev
CASE Ev OF
'STATISTIC_2DDRAW': BEGIN
if (Event.PRESS eq 2) then begin
scan2d_ROI_MMB,statistic_2dids
goto,set_return
end
if (Event.press eq 4) then begin
scan2d_ROI_MMB,statistic_2dids
statistic_2dPlot,statistic_2dids
end
if (Event.PRESS eq 1) then begin
boxregion,statistic_2dids,Event
scan2d_ROI_LMB,statistic_2dids
statistic_2dids.refresh = 1
goto,set_return
end
END
'STATISTIC_2DCLEAN': BEGIN
scan2d_ROI_default, statistic_2dids
END
'STATISTIC_2DFILE2': BEGIN
WIDGET_CONTROL,statistic_2dids.rptid,GET_VALUE=f
statistic_2dids.rpt = f
END
'STATISTIC_2DFILE': BEGIN
WIDGET_CONTROL,statistic_2dids.fileid,GET_VALUE=f
res = strpos(f(0),'.poly')
if res gt 0 then f = strmid(f(0),0,res)
statistic_2dids.file = f
statistic_2dids.picked = f+'.poly'
scan2d_ROI_readroi,statistic_2dids
END
'STATISTIC_2DBACKFLD': BEGIN
WIDGET_CONTROL,statistic_2dids.backid,GET_VALUE=ave
statistic_2dids.backave = ave
statistic_2dPlot,statistic_2dids
END
'STATISTIC_2DHIGHFLD': BEGIN
WIDGET_CONTROL,statistic_2dids.highid,GET_VALUE=ave
if ave lt statistic_2dids.backave then begin
res = dialog_message('High value must be greater than Low value.',/error)
goto,set_return
end
statistic_2dids.backave2 = ave
statistic_2dPlot,statistic_2dids
END
'STATISTIC_2DCOMMENT': BEGIN
WIDGET_CONTROL,statistic_2dids.commentid,GET_VALUE=f
statistic_2dids.comment = f
END
'STATISTIC_2DMULTIROI': BEGIN
len = strpos(statistic_2dids.picked,"_roi",/reverse_search)
if len ge 0 then class = strmid(statistic_2dids.file,0,len+1)
im0 = *statistic_2dids.im0
WIDGET_CONTROL,Event.top,/DESTROY
multiroi_pick,im0,class=class,comment=statistic_2dids.header(1), $
header=statistic_2dids.header(0) ;,Group=Event.top
return
END
'STATISTIC_2DBACKMODE': BEGIN
statistic_2dids.back = Event.Index
if Event.Index eq 2 then $
WIDGET_CONTROL,statistic_2dids.fileid,SET_VALUE=statistic_2dids.picked else $
WIDGET_CONTROL,statistic_2dids.fileid,SET_VALUE=statistic_2dids.file
if statistic_2dids.back eq 0 then $
WIDGET_CONTROL,statistic_2dids.rectbase,SENSITIVE=1 else $
WIDGET_CONTROL,statistic_2dids.rectbase,SENSITIVE=0
if statistic_2dids.back eq 2 then $
WIDGET_CONTROL,statistic_2dids.polybase,SENSITIVE=1 else $
WIDGET_CONTROL,statistic_2dids.polybase,SENSITIVE=0
if statistic_2dids.back eq 1 then $
WIDGET_CONTROL,statistic_2dids.backbase,SENSITIVE=1 else $
WIDGET_CONTROL,statistic_2dids.backbase,SENSITIVE=0
statistic_2dPlot,statistic_2dids
st0='**Press MMB to Query Pixel Values**'
if statistic_2dids.back eq 0 then $
st =[st0, $
'Press & move LMB in image area to define new ROI', $
'Use SaveRecROI button to save new RectROI ', $
'Use Refresh button to use whole image ROI', $
'Use ReadRectROI button to load old RectROI']
if statistic_2dids.back eq 1 then $
st =[st0, 'You are in the FilterROI mode', $
'Use Filter Low/High/SLIDERS to define ROI']
if statistic_2dids.back eq 2 then $
st =[st0, 'You are in the PolyROI mode', $
'Use DefPolyROI&Save to start new defROI funtion', $
'Press LMB in image area to define vertices',$
'Use ReadPolyROI load old polygon ROI']
WIDGET_CONTROL,statistic_2dids.message,SET_VALUE=st
END
'STATISTIC_2DBACKSLDR': BEGIN
WIDGET_CONTROL,Event.ID,GET_VALUE=v
WIDGET_CONTROL,statistic_2dids.backid,SET_VALUE=v
if v ge statistic_2dids.backave2 then begin
res = dialog_message('Low value must be less than High value.',/error)
WIDGET_CONTROL,statistic_2dids.backid,SET_VALUE=statistic_2dids.backave
WIDGET_CONTROL,Event.id,SET_VALUE=statistic_2dids.backave
goto,set_return
end
statistic_2dids.backave=v
statistic_2dPlot,statistic_2dids
END
'STATISTIC_2DHIGHSLDR': BEGIN
WIDGET_CONTROL,Event.ID,GET_VALUE=v
WIDGET_CONTROL,statistic_2dids.highid,SET_VALUE=v
if v lt statistic_2dids.backave then begin
res = dialog_message('High value must be greater than Low value.',/error)
WIDGET_CONTROL,statistic_2dids.highid,SET_VALUE=statistic_2dids.backave2
WIDGET_CONTROL,Event.ID,SET_VALUE=statistic_2dids.backave2
return
end
statistic_2dids.backave2=v
statistic_2dPlot,statistic_2dids
END
'STATISTIC_2DVERSUS': BEGIN
statistic_2dids.versus = Event.Index
if statistic_2dids.versus eq 0 then begin
WIDGET_CONTROL,statistic_2dids.minxid,SET_VALUE=statistic_2dids.min_i
WIDGET_CONTROL,statistic_2dids.minyid,SET_VALUE=statistic_2dids.min_j
WIDGET_CONTROL,statistic_2dids.maxxid,SET_VALUE=statistic_2dids.max_i
WIDGET_CONTROL,statistic_2dids.maxyid,SET_VALUE=statistic_2dids.max_j
x2 = statistic_2dids.cursor_i
y2 = statistic_2dids.cursor_j
st = 'CURSOR: Ix='+strtrim(x2,2)+', Jy='+ strtrim(y2,2)+','
im0 = *statistic_2dids.im0
stv= ' Pixel Value ='+strtrim(im0(x2,y2),2)
WIDGET_CONTROL,statistic_2dids.cursor,SET_VALUE=st
WIDGET_CONTROL,statistic_2dids.cursorv,SET_VALUE=stv
endif else begin
WIDGET_CONTROL,statistic_2dids.minxid,SET_VALUE=statistic_2dids.x(statistic_2dids.min_i)
WIDGET_CONTROL,statistic_2dids.minyid,SET_VALUE=statistic_2dids.y(statistic_2dids.min_j)
WIDGET_CONTROL,statistic_2dids.maxxid,SET_VALUE=statistic_2dids.x(statistic_2dids.max_i)
WIDGET_CONTROL,statistic_2dids.maxyid,SET_VALUE=statistic_2dids.y(statistic_2dids.max_j)
x2 = statistic_2dids.cursor_i
y2 = statistic_2dids.cursor_j
st = 'CURSOR: X='+strtrim(statistic_2dids.x(x2),2)+', Y='+ $
strtrim(statistic_2dids.y(y2),2)+','
stv= ' Pixel Value ='+strtrim(im0(x2,y2),2)
WIDGET_CONTROL,statistic_2dids.cursor,SET_VALUE=st
WIDGET_CONTROL,statistic_2dids.cursorv,SET_VALUE=stv
end
statistic_2dPlot,statistic_2dids
END
'STATISTIC_2DDONE': BEGIN
; device,set_graphics_function=3
WIDGET_CONTROL,Event.Top,/DESTROY
return
END
'STATISTIC_2DCOLOR': BEGIN
XLOADCT,GROUP=Event.Top
END
'STATISTIC_2DREADROI': BEGIN
if statistic_2dids.back eq 0 then scan2d_ROI_readroi ,statistic_2dids
END
'STATISTIC_2DREADFLTR': BEGIN
statistic_2dReadFilter,statistic_2dids,lower_b,upper_b
WIDGET_CONTROL,statistic_2dids.backid,SET_VALUE=lower_b
WIDGET_CONTROL,statistic_2dids.highid,SET_VALUE=upper_b
statistic_2dids.backave = lower_b
statistic_2dids.backave2 = upper_b
statistic_2dPlot,statistic_2dids
END
'STATISTIC_2DWRITEFLTR': BEGIN
WIDGET_CONTROL,statistic_2dids.backid,GET_VALUE=lower_b
WIDGET_CONTROL,statistic_2dids.highid,GET_VALUE=upper_b
statistic_2dWriteFilter,statistic_2dids,lower_b,upper_b
END
'STATISTIC_2DREADPOLYROI': BEGIN
statistic_2dPlot,statistic_2dids
END
'STATISTIC_2DDEFROI': BEGIN
text=['You are in the defining PolyROI mode:', $
'Left button to mark point', $
'Middle button to erase previous point', $
'Right button to close polygon region']
WIDGET_CONTROL,statistic_2dids.message,SET_VALUE=text
defroi_congrid,statistic_2dids,arr,xverts,yverts
scan2d_ROI_default, statistic_2dids
statistic_2dPlot,statistic_2dids
WIDGET_CONTROL,statistic_2dids.message,SET_VALUE='**Press MMB to Query Pixel Values**'
END
'STATISTIC_2DSAVEROI': BEGIN
found = findfile(statistic_2dids.file)
if found(0) ne '' then begin
st = ['File: '+statistic_2dids.file , 'already exists !!', $
'','Do you want to override the ROI file?']
res = dialog_message( st,/question)
if res eq 'No' then return
end
x = [statistic_2dids.x1,statistic_2dids.x2,statistic_2dids.y1, $
statistic_2dids.y2,statistic_2dids.factor]
xdr_open,unit,statistic_2dids.file,/write
xdr_write,unit,x
xdr_close,unit
END
'STATISTIC_2DREPORTVIEW': BEGIN
f = dialog_pickfile( path=statistic_2dids.rptpath,filter='*rpt*', $
title='View Rpt File',/READ)
if f eq '' then return
found = findfile(f) ; statistic_2dids.rpt)
if found(0) eq '' then begin
res = dialog_message(['ROI file : ','',f, $
'',' not found!'],/error)
return
end
xdisplayfile,f,GROUP=Event.Top
; res = cw_term(statistic_2dids.base,filename=f,/scroll)
END
'STATISTIC_2DRENAME': BEGIN
fn = statistic_2dids.rpt
res = rstrpos(statistic_2dids.rpt,!os.file_sep)
if res gt -1 then rpath = strmid(statistic_2dids.rpt,0,res)
rename_dialog,rpath,fn,'',GROUP=Event.top
END
'STATISTIC_2DREPLACE': BEGIN
scan2d_ROI_writeReport,statistic_2dids,/new
xdisplayfile,statistic_2dids.rpt,GROUP=Event.Top
END
'STATISTIC_2DREPORT': BEGIN
scan2d_ROI_writeReport,statistic_2dids
xdisplayfile,statistic_2dids.rpt,GROUP=Event.Top
; res = cw_term(statistic_2dids.base,filename=statistic_2dids.rpt,/scroll)
END
'STATISTIC_2DHELP': BEGIN
st = [$
'This program supports 4 types of ROI: rectangular region, low and high', $
'value filter, polygonal region, and multiple-ROI selections. The initial', $
'default mode is the rectangle ROI','',$
'It is assumed that the ROI file named ended with file type "roi.xdr"',$
'and the ROI report file ended with file type "roi.rpt". For accessing',$
'files not follow this name rule a user can modify the Filter field', $
'in the File Selection Dialog.','', $
'For easy of file management, it is recommanded that all the files ', $
'related to 2D-ROI are stored or grouped in a subdirectory "ROI"', $
'below the scan data directory.','', $
'For multiROIs picking mode, the ROI is re-defined every time the new image ',$
'is loading in. The default suffix file name roi.pick and rois.rpt are', $
'used for multiROIs.', $
' *** Brief User Interface Functions Given Below ***','', $
'Drawing Area Mouse Button Functions:',$
' RectROI mode',$
' Left Button - Press and move LMB to select the ROI, and ', $
' release and move LMB to show the ROI box', $
' At least two elements must be selected by ROI.', $
' Middle Button - Get CURSOR values in index#/values', $
' Right Button - Refresh the drawing area and ROI', $
' PolyROI mode',$
' Left button to mark point',$
' Middle button to erase previous point',$
' Right button to close region',$
'ROI Mode: ',$
' RectROI - Rectangle ROI mode', $
' FilterROI - Filter ROI based on Low and High values mode', $
' PolyROI - Polygon ROI mode', $
'MultiROIs... Button - Multiple ROIs selection program', $
'Help... Button - Display this help window',$
'Color... Button - Run XLOADCT program to select different color tables',$
'Done Button - Close this program', $
'','Rectangle ROI: ', $
' SaveRectROI Button - Save new rectangle ROI in ROIFile',$
' Refresh Button - Refresh the drawing area and recalculate the', $
' ROI statistics based on the whole image area', $
' ReadRectROI Button - Read ROI for either rectangle mode',$
'','Filter ROI: ', $
' SaveFltr - Save region defined by the low & high filters', $
' ReadFltr - Read region defined by the low & high filters', $
' Low: - Field to set low value',$
' Slider - Controls the low field value', $
' High: - Field to set high value',$
' Slider - Controls the high field value', $
'','Polygon ROI: ', $
' DefPolyROI&Save - Define and Save new polygon ROI in tmproi.xdr.poly',$
' statistics based on the read in ROI', $
' ReadPolyROI - Read polygon ROI from tmproi.xdr.poly',$
'', $
'Data:IM[wd x ht] - Shows the raw image dim and area total', $
'ROI: Im[I1:I2, J1:J2] - ROI dim and area total', $
' ROI Arerage: - Shows the mean average of ROI',$
' ROI Deviation: - Shows the standard deviation of ROI', $
' ROI Min: - Shows the minimum value in ROI',$
' @x: - Shows X index#/value of local Min', $
' @y: - Shows Y index#/value of local Min', $
' ROI Max: - Shows the maximum value in ROI', $
' @x: - Shows X index#/value of local Max', $
' @y: - Shows Y index#/value of local Max', $
' vs Index#/Value - Index#/Value option of x,y value', $
'Comment Field - Optional comment to ROI report', $
'', $
'ROIFile Menu - Select the desired ROIFile to be used ', $
' Field - Enter/show the ROIFile used ', $
'', $
'RptFile Menu - Select the desired RptFile to be used ', $
' Field - Enter/show the RptFile used ', $
' RenameRpt... - Rename the RptFile to a new name',$
' AppendRpt... - Append 2D statistic report data to RptFile',$
' ViewRpt... - View the 2D statistic RptFile',$
'', $
'CURSOR:... - MMB/RMB querys the X,Y,Z values at cursor',$
'', $
'Note: All the editable field must be entered with <CR>' $
]
xdisplayfile,'',title='Help... 2D ROI',text=st, GROUP=Event.Top
END
; Event for PDMENU3
'ROI2D_PDMENU3': ROI2D_PDMENU3_Event,statistic_2dids, Event
'PDMENU13': PDMENU13_Event,statistic_2dids, Event
ENDCASE
set_return:
WIDGET_CONTROL,Event.Top,SET_UVALUE=statistic_2dids
END
PRO scan2d_ROI_writeReport,statistic_2dids,new=new,debug=debug
if keyword_set(new) then openw,1,statistic_2dids.rpt,ERROR=err else $
openw,1,statistic_2dids.rpt,ERROR=err,/append
IF (err NE 0) then begin
PRINTF, -2, !ERR_STRING
close,1
return
end
xrange = statistic_2dids.xrange
yrange = statistic_2dids.yrange
if statistic_2dids.back then begin
xrange = [0,statistic_2dids.width-1]
yrange = [0,statistic_2dids.height-1]
end
printf,1,'===================================================='
printf,1,'Generated at: ',systime(0)
printf,1,'Header: ',statistic_2dids.header
printf,1,'Comment: ',statistic_2dids.comment
if statistic_2dids.back eq 2 then begin
printf,1,'ROI: Polygon region defined in ',statistic_2dids.picked
statistic_2dReadPolyROI,statistic_2dids,xverts,yverts,xv,yv,arr,r_index
if keyword_set(debug) then begin
print,xverts
print,yverts
print,xv
print,yv
print,arr
end
printf,1,'Xverts index:',xverts
printf,1,'Yverts index:',yverts
if n_elements(arr) eq 1 then begin
printf,1,'The polygon ROI is not suitable for this image.'
close,1
return
end
endif else begin