-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiroi_pick.pro
executable file
·1304 lines (1132 loc) · 37.8 KB
/
multiroi_pick.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.
;*************************************************************************
;
; multiroi_pick.pro
;
PRO graph_region,xl,yl,wd,ht,xsize,ysize
xl =30
yl =30
wd =300
ht =300
xsize = wd + 2*xl
ysize = ht + 2*yl
END
PRO defroi_zoombox,im,xl,yl,wd,ht,zoom_box,picke,background=background,region=region,delete=delete,oldpicke=oldpicke
if n_params() lt 5 then begin
str = [' Useing the zoombox to fine tune the ROIs. Marks the elements to be added or deleted.','', $
' Drag Left button to move zoom box. ',$
' Drag Middle button near a corner to resize box.',$
' Right button when done.' , '', $
'USAGE: defroi_zoombox, im, xl, yl, wd, ht, zoom_box=zoombox,...', '',$
'INPUT:',$
' im - image array corresponding to the TV image', $
' xl, yl - lower left corner of TV image', $
' wd, ht - total pixel width and height of image area', $
'OUTPUT:',$
' zoom_box - returns the [IL,JL,IR,JR] vector of selected region', $
'KEYWORD:',$
' BACKGROUNG - background color', $
' OLDPICKE - initial picked elements, required for window system', $
' REGION - specifies the desired region for add list', $
' DELETE - mark the list to be deleted from ROI' $
]
r = dialog_message(str,/info)
return
end
if n_elements(im) lt 4 then begin
r = dialog_message('Input error in Im',/Error)
return
end
region_no = 1
if keyword_set(region) then region_no = region
sz = size(im)
factor = [float(wd)/sz(1), float(ht)/sz(2)]
; catch,error_status
; if error_state ne 0 then print,!error_state.msg,!error_state.code
x0 = xl+wd/4
y0 = yl+ht/4
nx = wd/2
ny = ht/2
box_cursor,x0,y0,nx,ny,/INIT,/MESSAGE
ixl = 0 > fix((x0-xl)/factor(0)) < (sz(1)-1)
iyl = 0 > fix((y0-yl)/factor(1))< (sz(2)-1)
ixr = (ixl + ceil(nx/factor(0))) < (sz(1)-1)
iyr = (iyl + ceil(ny/factor(1))) < (sz(2)-1)
if iyl eq iyr and iyr gt 0 then iyl = iyr-1
if ixl eq ixr and ixr gt 0 then ixl = ixr-1
zoom_box = [ixl,iyl,ixr,iyr]
im_sub = im(ixl:ixr,iyl:iyr)
vmax = max(im)
vmin = min(im)
top = (!d.table_size-1) * (max(im_sub)-vmin)/(vmax-vmin)
oldpicke = reform(oldpicke,sz(1),sz(2))
oldpicke = oldpicke(ixl:ixr,iyl:iyr)
multiplier = [float(wd)/(ixr-ixl+1),float(ht)/(iyr-iyl+1)]
for jj=iyl,iyr do begin
j = jj - iyl
for ii=ixl,ixr do begin
i = ii - ixl
c_color = (!d.table_size-1) * (im_sub(i,j)-vmin)/(vmax-vmin)
xv = xl + multiplier(0)*[i,i+1,i+1,i,i]
yv = yl + multiplier(1)*[j,j,j+1,j+1,j]
polyfill,xv,yv,color = c_color,/device
end
end
for k=1,max(oldpicke) do begin
defroi_listregion,im_sub,oldpicke,region=k,/reverse
end
; call pick
;print,'oldpicke=',oldpicke
defroi_pick,im_sub,picke,region=region_no
;print,' picke=',picke
dx = ixr-ixl+1
ct = 0
for ij=0L,n_elements(picke)-1 do begin
if picke(ij) gt 0 then begin
i = ixl + ij MOD dx
j = iyl + ij / dx
nij = i + sz(1)* j
if ct eq 0 then elist = nij else $
elist = [elist, nij]
ct = ct + 1
end
end
; delete picked elements
if keyword_set(delete) then begin
if n_elements(elist) gt 0 then begin
defroi_listall,im,picke,minuslist=elist,charsize=1
endif else begin
defroi_listall,im,picke,charsize=1
end
return
end
; add picked elements
if n_elements(elist) gt 0 then begin
elist = [elist, region_no]
defroi_listall,im,picke,addlist=elist,charsize=1
endif else begin
defroi_listall,im,picke,charsize=1
end
END
PRO defroi_addlist,picke,elist
nel = n_elements(elist) - 1
region_no = elist(nel)
for i=0L,nel-1 do begin
ij = elist(i)
; if picke(ij) eq 0 then picke(ij) = region_no
if picke(ij) ne region_no then picke(ij) = region_no
end
END
PRO defroi_minuslist,picke,elist,region=region
; delete a selected region or marked elements
; 1 - delete selected region
if keyword_set(region) then begin
region_no = region
for i=0L,n_elements(picke)-1 do begin
if picke(i) eq region_no then picke(i)=0
end
return
end
; 2 - delete the marked elements
nel = n_elements(elist)
for i=0L,nel-1 do begin
ij = elist(i)
if picke(ij) gt 0 then picke(ij) = 0
end
END
PRO defroi_drawcolors,xl,yl,wd,ht,color=color
erase
scl = !d.table_size - 1
c_color=100L+100*256L+100*256L*256L
if keyword_set(color) then c_color = color*(1L+256L+256L*256L)
print,c_color
i=0
j=0
xv = xl + wd*[i,i+1,i+1,i,i]
yv = yl + ht*[j,j,j+1,j+1,j]
polyfill,xv,yv,color = c_color,/device
END
PRO defroi_refresh,im,width=width,height=height,xpos=xpos,ypos=ypos,print=print,charsize=charsize,background=background
graph_region,xl,yl,wd,ht
if keyword_set(background) then erase,background else $
erase
TVSCL,congrid(im,wd,ht),xl,yl
END
PRO defroi_listregion,im,picke,region_data,region=region,refresh=refresh,width=width,height=height,xpos=xpos,ypos=ypos,print=print,charsize=charsize,reverse=reverse
;
; NAME:
; DEFROI_LISTREGION
;
; PURPOSE:
; List region of interest
;
; INPUT:
; Im - image array
; Picke - vector of selected ROI numbers in byte
; Region_data - returns the data structure for a selected region
;
; region_data = { nelem: sel_no, $ number of elements in region
; el_list: el_list, $ elements indices in region
; total: sel_total, $ Total
; ave: ave, $ Average
; var: var, $ Variance
; dev: dev, $ Standard deviation
; min: temp_min, $ Minimum in region
; max: temp_max $ Maximum in region
; KEYWORD:
; REGION - specifies the region number, default 1
; CHARSIZE - if specified, mark the region with the region number
; PRINT - list the values of the region element
;
; xl=80
; yl=80
; wd=340
; ht=340
graph_region,xl,yl,wd,ht
if keyword_set(refresh) then TVSCL,congrid(im,wd,ht),xl,yl
sz = size(im)
multiplier = [float(wd)/sz(1),float(ht)/sz(2)]
region_no = region
nregion = max(picke)
if region_no gt nregion then begin
str = 'Error: ROI '+strtrim(nregion,2) + ' not found!'
r = dialog_message(str,/error)
return
end
nelem = n_elements(picke)
csize=1
if keyword_set(charsize) then csize=charsize
if keyword_set(print) then $
print,' IJ I J IM(I,J) ROI#'
xtr = strtrim(region_no,2)
orient = 45
if keyword_set(reverse) then orient = -45
device,set_graphics_function=6
el_list = where(picke eq region_no)
if n_elements(el_list) gt 1 then begin
sel_list = im(el_list)
for ij=0L,n_elements(el_list) -1 do begin
i = el_list(ij) mod sz(1)
j = el_list(ij) / sz(1)
xv = xl + multiplier(0)*[i,i+1,i+1,i,i]
yv = yl + multiplier(1)*[j,j,j+1,j+1,j]
polyfill,xv,yv,line_fill=1,orientation=orient,/device
if csize gt 0 then $
xyouts,xv(0),yv(0),xtr,/device,charsize=csize
if keyword_set(print) then print,ij,i,j,im(i,j),region_no
end
device,set_graphics_function=3
sel_total = total(sel_list)
sel_no = n_elements(sel_list)
res = moment(sel_list,sdev=dev,mdev=mdev)
ave = res(0)
var = res(1)
temp_min = min(sel_list,jmin)
temp_max = max(sel_list,jmax)
min_i = el_list(jmin) MOD sz(1)
min_j = el_list(jmin) / sz(1)
max_i = el_list(jmax) MOD sz(1)
max_j = el_list(jmax) / sz(1)
end
if n_elements(sel_no) then $
region_data = { nelem: sel_no, $
el_list: el_list, $
total: sel_total, $
ave: ave, $
var: var, $
dev: dev, $
min_i: min_i, $
min_j: min_j, $
max_i: max_i, $
max_j: max_j, $
min: temp_min, $
max: temp_max $
}
END
PRO defroi_listall,im,picke,width=width,height=height,xpos=xpos,ypos=ypos,file=file,print=print,charsize=charsize,addlist=addlist,minuslist=minuslist
;
; CHARSIZE - if specified, mark the pixel with region number
; PRINT - list the values of the region element
; file - override the default filename 'roi.pick' if file is specified
;
;x0=80
;y0=80
;wd=340
;ht=340
graph_region,x0,y0,wd,ht
csize = 0.
if keyword_set(charsize) then csize=charsize
if keyword_set(width) then wd = width
if keyword_set(height) then ht = height
if keyword_set(xpos) then x0 = xpos
if keyword_set(ypos) then y0 = ypos
erase
TVSCL,congrid(im,wd,ht),x0,y0
sz = size(im)
multiplier = [wd/sz(1),ht/sz(2)]
filename = 'roi.pick'
if keyword_set(file) then filename = file
nelem = sz(1)*sz(2)
picke = make_array(nelem,/long)
found = findfile(filename,count=ct)
if ct gt 0 then begin
xdr_open,unit,filename
xdr_read,unit,picke
xdr_close,unit
end
; redefine the region of interest
if nelem lt n_elements(picke) then begin
addlist = 1
picke = make_array(nelem,/long)
end
if nelem gt n_elements(picke) then begin
addlist = 1
picke = make_array(nelem,/long)
end
if keyword_set(addlist) then begin
defroi_addlist,picke,addlist
xdr_open,unit,filename,/write
xdr_write,unit,picke
xdr_close,unit
end
if keyword_set(minuslist) then begin
if minuslist(0) lt 0 then $
defroi_minuslist,picke,region=-minuslist(0) else $
defroi_minuslist,picke,minuslist
xdr_open,unit,filename,/write
xdr_write,unit,picke
xdr_close,unit
end
found = findfile(filename,count=ct)
if ct eq 0 then begin
er = dialog_message(filename+' not found',/Error)
return
end
max_region = max(picke)
; marked the readin picked elements
for k=1,max_region do begin
defroi_listregion,im,picke,region_data,region=k,charsize=csize ;,/print
end
END
PRO defroi_pick,im,picke,width=width,height=height,xpos=xpos,ypos=ypos,listall=listall,clear=clear,new=new,modify=modify,print=print,region=region,ave=ave,dev=dev,var=var,readonly=readonly,charsize=charsize
; LMB - toggle the pixel selection, the selected pixel is marked by lines
; MMB - print the data value at the mouse cursor position
; RMB - terminate the selection and update the saved ROI, default filename
; 'roi.pick'
; INPUT
; Im - input image array
; Picke - returns the vector indicator 1 - picked, 0 - not picked
; KEYWORD
; XPOS - image lower left pixel position
; YPOS - image lower bottom pixel position
; WIDTH - total width of pixels used for displaying im
; HEIGHT - total height of pixels used for displaying im
; CLEAR - refresh the TV
; NEW - saving as new roi.pick file
; MODIFY - read in previous roi.pick and let the user modify the ROI by
; toggling the desired pixel
; PRINT - if specified, print the array result
; READONLY - only read the region data no modification allowed
; CHARSIZE - charsize mark the picked pixel
; REGION - specified the region number to be examined, default 1
; EL_LIST - returns the selected element list for the specified region
; AVE - returns the average value for the specified region
; DEV - returns the standard deviation value for the specified region
; VAR - returns the variance for the specified region
region_no = 1
if keyword_set(region) then region_no = region
csize = 1
if keyword_set(charsize) then csize=charsize
;x0=80
;y0=80
;wd=340
;ht=340
graph_region,x0,y0,wd,ht
if keyword_set(width) then wd = width
if keyword_set(height) then ht = height
if keyword_set(xpos) then x0 = xpos
if keyword_set(ypos) then y0 = ypos
; TVSCL,congrid(im,wd,ht),x0,y0
sz = size(im)
multiplier = [float(wd)/sz(1),float(ht)/sz(2)]
filename = 'roi.pick'
if keyword_set(modify) then begin
if strlen(strtrim(modify,2)) gt 1 then filename = modify
end
vmax = max(im)
vmin = min(im)
nelem = sz(1)*sz(2)
picke = make_array(nelem,/long)
found = findfile(filename,count=ct)
if ct gt 0 then begin
if keyword_set(modify) then begin
xdr_open,unit,filename
xdr_read,unit,picke
xdr_close,unit
; marked the readin picked elements
for ij=0L,nelem-1 do begin
if picke(ij) eq region_no then begin
i = ij mod sz(1)
j = ij / sz(1)
; xv = x0 + multiplier(0)*[i,i+1,i+1,i,i]
; yv = y0 + multiplier(1)*[j,j,j+1,j+1,j]
; polyfill,xv,yv,line_fill=1,orientation=45,/device
if keyword_set(print) then print,ij,i,j,im(i,j),region_no
if n_elements(sel_list) eq 0 then begin
sel_list = im(i,j)
el_list = ij
end else begin
sel_list = [sel_list, im(i,j)]
el_list = [el_list,ij]
end
end
end
if n_elements(sel_list) gt 1 then begin
sel_total = total(sel_list)
sel_no = n_elements(sel_list)
res = moment(sel_list,sdev=dev,mdev=mdev)
ave = res(0)
var = res(1)
temp_min = min(sel_list,jmin)
temp_max = max(sel_list,jmax)
min_i = jmin MOD sz(1)
min_j = jmin / sz(1)
max_i = jmax MOD sz(1)
max_j = jmax / sz(1)
end
if keyword_set(readonly) then begin
device,set_graphics_function=3
return
end
end
end ; if else new=1
device,set_graphics_function=6
str = ['You are in ROI discrete pixel selection mode', $
'for region # ='+strtrim(region_no), $
'LMB to pick/unpick the pixel, RMB to stop selection.']
r = dialog_message(str,/info)
cursor,x,y,/device,/down
while (!mouse.button ne 4) do begin
i = fix((x-x0)/multiplier(0))
j = fix((y-y0)/multiplier(1))
ij = j*sz(1)+i
if !mouse.button eq 1 then begin
if ij lt nelem then begin
if picke(ij) eq 0 then picke(ij) = region_no else picke(ij)=0
; mark/unmark the picked elements
xv = x0 + multiplier(0)*[i,i+1,i+1,i,i]
yv = y0 + multiplier(1)*[j,j,j+1,j+1,j]
polyfill,xv,yv,line_fill=1,orientation=-45,/device
if keyword_set(print) then print,ij,i,j,im(i,j),region_no
end
end
cursor,x,y,/device,/DOWN
end
device,set_graphics_function=3
if !mouse.button eq 4 then begin
device,set_graphics_function=3
if keyword_set(modify) or keyword_set(new) then begin
xdr_open,unit,filename,/write
xdr_write,unit,picke
xdr_close,unit
end
; defroi_listall,im,charsize=csize
return
end
END
PRO multiroi_help
str = [ 'For detail information, please refer','', $
' http://www.aps.anl.gov/~cha/multiROI.html', '', $
'MULTIROI_PICK allows the user flexiblly redefine the ROIs by', $
'free-hand drawing and picking the pixel elements.', $
'Element selected is marked with hash line and associated ROI number', $
'','The function of each button are listed below:','', $
'Drawing Area- Draw the marked image area', $
'Msg Info - Hint about mouse operation below the drawing area', $
'Help... - Show this on-line help', $
'Read ROIs...- Read a ROIs definition file', $
'Save ROIs...- Save / update the ROIs definition file', $
'Tiff/Png/Pict - Save the ROIs to a TIFF file', $
'Color... - Change the IDL window color map ', $
'Refresh - Refresh TV image', $
'ShowAll ROIs - Redraw and mark all the selected elements', $
'ROI #: - Show list of existing ROIs defined for the image', $
' Select the number will re-display the ROI statistic', $
' in the scroll area', $
'Draw PolyROI - Redraw the PolyROI for a selected ROI #', $
'Modify ROI - Select/unselect pixels for a selected ROI #', $
' (LMB to pick/unpick pixel, RMB to stop) ', $
'Add ROI - Add an additional ROI to the ROI # list', $
' (LMB to pick/unpick pixel, RMB to stop) ', $
'Del ROI - Delete the selected ROI', $
'Zoom Add - Zoom a box region, pick pixel elements to be added to the ROI', $
'Zoom Del - Zoom a box region, pick pixel elements to be deleted from the ROI', $
'Query Image - Query image mode, RMB to stop', $
'Offset Val: - Offset value for the ROI statistic calculation', $
'Charsize: - Specify the charsize used in marking the pixel', $
'Scroll Area - Display the ROI statistics if new ROI# is selected', $
'Save As ... - Save the statistic scroll window content to a disk file', $
'Print - Print the statistic scroll window content to printer', $
'Clear - Clear the statistic scroll window', $
'Bg color: - Slider control for displaying query image data', $
'ROIsTIFF - Show TIFF filename corresponding to ROIs filename ', $
'Done - Close the multi-roi selection program' $
]
r = dialog_message(str,/info)
END
PRO multiroi_pickregion,defroi_pickinfo,region
im = defroi_pickinfo.im0
picke = defroi_pickinfo.picke
nelem = total(picke eq region)
if nelem gt 0 then begin
if defroi_pickinfo.offset ne 0. then im = im - defroi_pickinfo.offset
defroi_refresh,im
defroi_listregion,im,picke,region_data,region=region
str = [ '===========================', $
'Report generated at: ' + systime(0), $
defroi_pickinfo.comment, $
'===========================', $
'REGION OF INTEREST : '+strtrim(region,2)]
if n_elements(region_data) eq 0 then $
str = [str, $
"ERROR: no statistic for region " + string(region), $
' at 2 pixels required for statistics ', $
"***************************",'']
if n_elements(region_data) then begin
str = [str, $
'MINIMUM: '+strtrim(region_data.min,2)+' I='+strtrim(region_data.min_i,2)+' J='+strtrim(region_data.min_j,2), $
'MAXIMUM: '+strtrim(region_data.max,2)+' I='+strtrim(region_data.max_i,2)+' J='+strtrim(region_data.max_j,2), $
'TOTAL: '+strtrim(region_data.total,2), $
'AVERAGE: '+strtrim(region_data.ave,2), $
'VARIANCE: '+strtrim(region_data.var,2), $
'DEVIATION: '+strtrim(region_data.dev,2), $
'OFFSET: '+strtrim(defroi_pickinfo.offset,2), $
'NELEM: '+strtrim(region_data.nelem,2), $
'N I J IM(I,J)-Offset' $
]
st = strarr(region_data.nelem)
sz = size(im)
for ij=0L,region_data.nelem-1 do begin
i = region_data.el_list(ij) MOD sz(1)
j = region_data.el_list(ij) / sz(1)
st(ij) = strtrim(ij,2)+string(i)+string(j)+string(im(i,j))
end
str = [str,st]
end
WIDGET_CONTROL,defroi_pickinfo.text,SET_VALUE=str,/append
end
END
PRO multiroi_picklistall,defroi_pickinfo
im = defroi_pickinfo.im0
picke = defroi_pickinfo.picke
nregion = max(picke)
FOR region=1,nregion DO BEGIN
multiroi_pickregion,defroi_pickinfo,region
END
END
PRO multiroi_pick_Event, Event
WIDGET_CONTROL,Event.Id,GET_UVALUE=Ev
WIDGET_CONTROL, Event.Top, GET_UVALUE=defroi_pickinfo
xsize = defroi_pickinfo.xsize
ysize = defroi_pickinfo.ysize
CASE Ev OF
'DEFROIPICK_DRAW': BEGIN
END
'DEFROIPICK_DONE': BEGIN
WIDGET_CONTROL,Event.Top,/DESTROY
return
END
'DEFROIPICK_REFRESH': BEGIN
defroi_refresh,defroi_pickinfo.im0
END
'DEFROIPICK_HELP': BEGIN
multiroi_help
END
'DEFROIPICK_COLOR': BEGIN
xloadct,GROUP=Event.top
END
'DEFROIPICK_ALL': BEGIN
WIDGET_CONTROL,defroi_pickinfo.text,SET_VALUE=''
multiroi_picklistall,defroi_pickinfo
im = defroi_pickinfo.im0
WIDGET_CONTROL,/HOURGLASS
defroi_listall,im,picke,charsize=defroi_pickinfo.csize
defroi_pickinfo.picke = picke
END
'DEFROIPICK_LISTREGION': BEGIN
im = defroi_pickinfo.im0
picke = defroi_pickinfo.picke
region = defroi_pickinfo.region_id
defroi_refresh,im
defroi_listregion,im,picke,region_data,region=region
END
'DEFROIPICK_LIST': BEGIN
WIDGET_CONTROL,defroi_pickinfo.text,SET_VALUE=''
r = widget_info(Event.Id,/list_select)
defroi_pickinfo.region_id = r+1
im = defroi_pickinfo.im0
picke = defroi_pickinfo.picke
region = defroi_pickinfo.region_id
multiroi_pickregion,defroi_pickinfo,region
END
'DEFROIPICK_DEL': BEGIN
picke = defroi_pickinfo.picke
region = defroi_pickinfo.region_id
polyfill,[0,xsize,xsize,0],[ysize-30,ysize-30,ysize,ysize], $
color=defroi_pickinfo.bg,/device
xyouts,1,ysize-19,'***Del ROI '+strtrim(region,2)+' ***',/device
im = defroi_pickinfo.im0
defroi_listall,im,picke,charsize=defroi_pickinfo.csize,minuslist=-region
defroi_pickinfo.picke = picke
polyfill,[0,xsize,xsize,0],[ysize-30,ysize-30,ysize,ysize], $
color=defroi_pickinfo.bg,/device
END
'DEFROIPICK_ADD': BEGIN
picke = defroi_pickinfo.picke
region = max(picke) + 1
polyfill,[0,xsize,xsize,0],[ysize-30,ysize-30,ysize,ysize], $
color=defroi_pickinfo.bg,/device
xyouts,1,ysize-19,'***Add ROI '+strtrim(region,2)+': LMB pick element, RMB stop***',/device
defroi_pickinfo.region_max = region
str = string( defroi_pickinfo.list(1:defroi_pickinfo.region_max))
WIDGET_CONTROL,defroi_pickinfo.listwid,set_value=str
WIDGET_CONTROL, defroi_pickinfo.listwid, SET_LIST_SELECT=defroi_pickinfo.region_max-1
im = defroi_pickinfo.im0
defroi_listall,im,picke,charsize=defroi_pickinfo.csize
; add the new region selection
defroi_pickinfo.region_id = defroi_pickinfo.region_max
region = defroi_pickinfo.region_id
; defroi_pick,im,picke,region=region,/modify
defroi_pick,im,picke,region=region,modify='roi.pick'
defroi_pickinfo.picke = picke
defroi_listall,im,picke,charsize=defroi_pickinfo.csize
polyfill,[0,xsize,xsize,0],[ysize-30,ysize-30,ysize,ysize], $
color=defroi_pickinfo.bg,/device
END
'DEFROIPICK_QUERY': BEGIN
if defroi_pickinfo.help then $
str="Use Right Mouse Button to stop query."
WIDGET_CONTROL,defroi_pickinfo.msg,SET_VALUE=str
cursor,x,y,/device,/change
while (!mouse.button ne 4) do begin
x = !mouse.x
y = !mouse.y
im = defroi_pickinfo.im0
sz = size(im)
zoom = [float(defroi_pickinfo.wd)/sz(1),float(defroi_pickinfo.ht)/sz(2)]
i = fix((x - defroi_pickinfo.xl)/zoom(0))
j = fix((y - defroi_pickinfo.yl)/zoom(1))
if i lt 0 then i = 0
if j lt 0 then j = 0
if i ge sz(1) then i = sz(1) - 1
if j ge sz(2) then j = sz(2) - 1
str = '***IMAGE('+strtrim(i,2)+','+strtrim(j,2)+')='+strtrim(im(i,j),2)
cursor,x,y,/device,/change
device,set_graphics_function=3
polyfill,[0,xsize,xsize,0],[ysize-30,ysize-30,ysize,ysize], $
color=defroi_pickinfo.bg,/device
xyouts,1,ysize-19,str,/device,charsize=1.5 ;2
end
END
'DEFROIPICK_DRAWROI': BEGIN
polyfill,[0,xsize,xsize,0],[ysize-30,ysize-30,ysize,ysize], $
color=defroi_pickinfo.bg,/device
xyouts,1,ysize-19,'***Draw PolyROI',/device
im = defroi_pickinfo.im0
sz = size(im)
defroi_refresh,im
xw = defroi_pickinfo.wd
yw = defroi_pickinfo.ht
xl = defroi_pickinfo.xl
yl = defroi_pickinfo.yl
zoom = [float(xw)/sz(1),float(yw)/sz(2)]
r = defroi(xw,yw,xverts,yverts,x0=xl,y0=yl)
xverts = float(xverts) /zoom(0)
yverts = float(yverts) /zoom(1)
xv = fix(xverts+0.5)
yv = fix(yverts+0.5)
arr = polyfillv(xv,yv,sz(1),sz(2))
picke = defroi_pickinfo.picke
defroi_listall,im,picke,addlist=[arr,defroi_pickinfo.region_id],charsize=defroi_pickinfo.csize
defroi_pickinfo.picke = picke
polyfill,[0,xsize,xsize,0],[ysize-30,ysize-30,ysize,ysize], $
color=defroi_pickinfo.bg,/device
END
'DEFROIPICK_MOD': BEGIN
region = defroi_pickinfo.region_id
polyfill,[0,xsize,xsize,0],[ysize-30,ysize-30,ysize,ysize], $
color=defroi_pickinfo.bg,/device
xyouts,1,ysize-19,'***Modify ROI '+strtrim(region,2)+': LMB pick element, RMB stop***',/device
im = defroi_pickinfo.im0
defroi_listall,im,picke,charsize=defroi_pickinfo.csize
defroi_pick,im,picke,region=region,modify='roi.pick'
defroi_pickinfo.picke = picke
defroi_listall,im,picke,charsize=defroi_pickinfo.csize
polyfill,[0,xsize,xsize,0],[ysize-30,ysize-30,ysize,ysize], $
color=defroi_pickinfo.bg,/device
END
'DEFROIPICK_ZOOMDEL': BEGIN
polyfill,[0,xsize,xsize,0],[ysize-30,ysize-30,ysize,ysize], $
color=defroi_pickinfo.bg,/device
xyouts,1,ysize-19,'***Zoom Del: LMB pick element, RMB stop***',/device
if defroi_pickinfo.help then begin
str =['Zoom Del Mode: resize zoom box, delete pixels', $
'Zoom Box Control: ',$
' Drag LMB - Reposition box',$
' Drag RMB - Resize box', $
' Click RMB - Accept box region', $
'Select Pixels:', $
' LMB - Pickup the pixels to be deleted', $
' RMB - Done with selection ']
WIDGET_CONTROL,defroi_pickinfo.msg,SET_VALUE=str
end
im = defroi_pickinfo.im0
xl = defroi_pickinfo.xl
yl = defroi_pickinfo.yl
wd = defroi_pickinfo.wd
ht = defroi_pickinfo.ht
picke = defroi_pickinfo.picke
region = defroi_pickinfo.region_id
defroi_zoombox,im,xl,yl,wd,ht,zoom_box,picke,oldpicke=picke,region=region,/delete
defroi_pickinfo.picke = picke
polyfill,[0,xsize,xsize,0],[ysize-30,ysize-30,ysize,ysize], $
color=defroi_pickinfo.bg,/device
END
'DEFROIPICK_ZOOMADD': BEGIN
region = defroi_pickinfo.region_id
polyfill,[0,xsize,xsize,0],[ysize-30,ysize-30,ysize,ysize], $
color=defroi_pickinfo.bg,/device
xyouts,1,ysize-19,'***Zoom Add '+strtrim(region,2)+': LMB pick element, RMB stop***',/device
if defroi_pickinfo.help then begin
str =['Zoom Add Mode: resize box, pick pixel', $
'Zoom Box Control: ',$
' Drag LMB - Reposition box',$
' Drag RMB - Resize box', $
' Click RMB - Accept box region', $
'Select Pixels:', $
' LMB - Pickup the pixel', $
' RMB - Done with selection']
WIDGET_CONTROL,defroi_pickinfo.msg,SET_VALUE=str
end
im = defroi_pickinfo.im0
xl = defroi_pickinfo.xl
yl = defroi_pickinfo.yl
wd = defroi_pickinfo.wd
ht = defroi_pickinfo.ht
picke = defroi_pickinfo.picke
defroi_zoombox,im,xl,yl,wd,ht,zoom_box,picke,oldpicke=picke,region=defroi_pickinfo.region_id
defroi_pickinfo.picke = picke
polyfill,[0,xsize,xsize,0],[ysize-30,ysize-30,ysize,ysize], $
color=defroi_pickinfo.bg,/device
END
'DEFROIPICK_ROIREAD': BEGIN
path=defroi_pickinfo.path
filename = dialog_pickfile(filter='*roi.pick*', $
path=defroi_pickinfo.path, Title='Read ROIs File',$
GET_PATH=gp,/READ,/MUST_EXIST)
if filename eq '' then return
defroi_pickinfo.roifile = filename
WIDGET_CONTROL,defroi_pickinfo.text,SET_VALUE=filename
p1 = strpos(filename,!os.file_sep,/reverse_search)
name = strmid(filename,p1+1,strlen(filename)-p1)
defroi_pickinfo.tiffname = filename+'.tiff'
WIDGET_CONTROL,defroi_pickinfo.tiffwid,SET_VALUE=name+'.tiff'
xdr_open,unit,filename
xdr_read,unit,picke,ERROR=er
if er ne 0 then begin
xdr_close,unit
r = dialog_message('Error: wrong type of data picked',/error)
return
end
xdr_close,unit
xdr_open,unit2,'roi.pick',/write
xdr_write,unit2,picke
xdr_close,unit2
im = defroi_pickinfo.im0
defroi_listall,im,picke,charsize=defroi_pickinfo.csize
defroi_pickinfo.picke = picke
nregion = max(picke)
if nregion gt 1 then begin
defroi_pickinfo.region_max = nregion
str = string( defroi_pickinfo.list(1:defroi_pickinfo.region_max))
WIDGET_CONTROL,defroi_pickinfo.listwid,set_value=str
end
END
'DEFROIPICK_ROISAVE': BEGIN
file0 = 'roi.pick'
path=defroi_pickinfo.path
file1 = defroi_pickinfo.roifile
p = strpos(file1,!os.file_sep,/reverse_search)
file = strmid(file1,p+1,strlen(file1)-p-1)
filename = dialog_pickfile(filter='*roi.pick*', $
path=defroi_pickinfo.path, Title='Save ROIs File',$
file=file1, $
GET_PATH=gp,/WRITE)
if filename eq '' then return
WIDGET_CONTROL,defroi_pickinfo.text,SET_VALUE=filename
p1 = strpos(filename,!os.file_sep,/reverse_search)
name = strmid(filename,p1+1,strlen(filename)-p1)
defroi_pickinfo.roifile = filename
defroi_pickinfo.tiffname = filename+'.tiff'
WIDGET_CONTROL,defroi_pickinfo.tiffwid,SET_VALUE=name+'.tiff'
xdr_open,unit,'roi.pick'
xdr_read,unit,picke
xdr_close,unit
xdr_open,unit2,filename,/write
xdr_write,unit2,picke
xdr_close,unit2
END
'DEFROIPICK_ROITIFF': BEGIN
pngname = defroi_pickinfo.tiffname
type = defroi_pickinfo.tifftype
tvlct,r,g,b,/get
case type of
0: save_tiff,file=pngname,win=defroi_pickinfo.wid,path=defroi_pickinfo.path
1: save_png,file=pngname,win=defroi_pickinfo.wid,path=defroi_pickinfo.path
2: save_pict,file=pngname,win=defroi_pickinfo.wid,path=defroi_pickinfo.path
endcase
; print,'pngname=',pngname
END
'DEFROIPICK_TEXT': BEGIN
Print, 'Event for DEFROIPICK_TEXT'
END
'DEFROIPICK_SAVEIMG': BEGIN
type = WIDGET_INFO(Event.ID,/DROPLIST_SELECT)
name = defroi_pickinfo.roifile
case type of
0: newname = name + '.tiff'
1: newname = name + '.png'
2: newname = name + '.pict'
endcase
p1 = strpos(newname,!os.file_sep,/reverse_search)
name = strmid(newname,p1+1,strlen(newname)-p1)
WIDGET_CONTROL,defroi_pickinfo.tiffwid,SET_VALUE = name
defroi_pickinfo.tiffname = newname
defroi_pickinfo.tifftype = type
;print,'newname=',newname
END
'DEFROIPICK_TIFFNAME': BEGIN
WIDGET_CONTROL,Ev.Id,GET_VALUE=st
defroi_pickinfo.tiffname = st(0)
END
'DEFROIPICK_TEXTSAVE': BEGIN
filename = dialog_pickfile(filter='*rois.rpt*', $
path=defroi_pickinfo.path, $
file = defroi_pickinfo.class+'rois.rpt', $
get_path=gpath,/write,title='Save rois.rpt')
if filename eq gpath then begin
r = dialog_message('Error: the file name end with "rois.rpt" is required',/error)
return
end
found = findfile(filename,count=ct)
if ct gt 0 then begin
r = dialog_message(['Overwite the existing file:',filename],/question)
if r eq 'No' then return
end
WIDGET_CONTROL,defroi_pickinfo.text,GET_VALUE=str
openw,1,filename
for i=0,n_elements(str)-1 do printf,1,str(i)
close,1
END
'DEFROIPICK_TEXTPRINT': BEGIN
WIDGET_CONTROL,defroi_pickinfo.text,GET_VALUE=str
openw,1,'rois.rpt'
for i=0,n_elements(str)-1 do printf,1,str(i)
close,1
PS_print,'rois.rpt'
END
'DEFROIPICK_TEXTCLEAR': BEGIN
WIDGET_CONTROL,defroi_pickinfo.text,SET_VALUE=''
END
'DEFROIPICK_BACKGROUND': BEGIN
; WIDGET_CONTROL,defroi_pickinfo.slider,GET_VALUE=bg
; defroi_pickinfo.bg = bg
; defroi_refresh,defroi_pickinfo.im0
; picke = defroi_pickinfo.picke
; im = defroi_pickinfo.im0
; device,set_graphics_function=6
; defroi_listall,im,picke,charsize=1
; device,set_graphics_function=3
END
'DEFROIPICK_OFFSET': BEGIN
WIDGET_CONTROL,defroi_pickinfo.offwid,GET_VALUE=str
defroi_pickinfo.offset = str
END
'DEFROIPICK_CSIZE': BEGIN
WIDGET_CONTROL,defroi_pickinfo.csizewid,GET_VALUE=str
defroi_pickinfo.csize = str
print,defroi_pickinfo.csize
END
ENDCASE
WIDGET_CONTROL,defroi_pickinfo.msg,SET_VALUE=''
WIDGET_CONTROL, defroi_pickinfo.base, SET_UVALUE=defroi_pickinfo
END
PRO multiroi_pick,im, GROUP=Group,CLASS=Class,bg=bg,comment=comment,header=header
;+
; NAME:
; MULTIROI_PICK
;
; PURPOSE:
; This routine provide a flexible 2D image Region Of Interest statistic
; program. It supports multiple ROIs by allowing the user dynamically
; to select the ROIs and modify the ROIs by toggling the pixels.
;
; It is a complete mouse driven program. It let user easily generated
; the statistic ROI report for an arbitrary input 2D image.
;
; CATEGORY:
; Widgets.
;