Repository navigation
Expand file tree
/
Copy pathMP3.m
More file actions
5859 lines (4845 loc) · 246 KB
/
Copy pathMP3.m
File metadata and controls
5859 lines (4845 loc) · 246 KB
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
function varargout = MP3(varargin)
% MP3 MATLAB code for MP3.fig
% MP3, by itself, creates a new MP3 or raises the existing
% singleton*.
%
% H = MP3 returns the handle to a new MP3 or the handle to
% the existing singleton*.
%
% MP3('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MP3.M with the given input arguments.
%
% MP3('Property','Value',...) creates a new MP3 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before MP3_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to MP3_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help MP3
% Last Modified by GUIDE v2.5 26-Apr-2019 16:40:28
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @MP3_OpeningFcn, ...
'gui_OutputFcn', @MP3_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before MP3 is made visible.
function MP3_OpeningFcn(hObject, ~, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to MP3 (see VARARGIN)
% Choose default command line output for MP3
handles.output = hObject;
% Add path to all the files in the MATLAB search path
p = mfilename('fullpath');
warning off
rmpath(genpath(fileparts(p)))
warning on
addpath(genpath(fileparts(p)),'-begin');
% init stuct/variables
handles.VOIs = {'Other'};
handles.histo = {'Other'}; %{'Pimo', 'ColIV', 'Tc+I_cerveau', 'Tc+I_ref'};
handles.resolution = [1 64 112 128 192 256 384 512 3000];
handles.colors ={'b', 'g', 'm', 'c', 'r', 'k', 'y', 'navy',...
'u1','turquoise','slateblue', 'springgreen', 'maroon',...
'purple', 'u2', 'olive', 'u3','chartreuse', 'u4', 'sky',...
'u5', 'orange', 'u6', 'u7', 'u8', 'gray'};
%handles.colors_rgb = [0 0 1; 0 1 0; 1 1 0; 1 0 1; 0 1 1; 1 0 0; 0 0 0; 1 1 1];
load(which('rgb_color_table.mat'), 'num');
handles.colors_rgb = num;
handles.colormap = get(handles.MP3_colormap_popupmenu,'String');
handles.markers ={'o','s', 'd', 'p', 'h', '+', '*', 'x'};
table_data(1,1) = {'Voxel values'};
set(handles.MP3_table_pixel_values, 'Data', table_data);
set(handles.MP3_table1, 'Data', {'', '', '', '', ''});
handles.table1.cluster = [];
handles.table1.cluster_row = [];
handles.mode = 1;
handles.view_mode = 'Axial';
handles.display_option.view_pixel_on_map = 0;
handles.display_option.view_pixel_on_plot = 0;
handles.display_option.view_plot = 1;
handles.display_option.manual_contrast = 0;
set(handles.MP3_menu_view_plot, 'Check', 'on');
for i=1:4
stri = num2str(i);
set(eval(['handles.MP3_data', stri, '_echo_slider']), 'Visible', 'off');
set(eval(['handles.MP3_data', stri, '_expt_slider']), 'Visible', 'off');
end
set(handles.MP3_PRM_slider_trans, 'Visible', 'off');
% add MRIManager.jar to the classpath (dynamic classpath)
[filepath,name,ext] = fileparts(which('MRIManager.jar'));
javaclasspath(fullfile(filepath,[name,ext]));
% save the java skin used
handles.original_Java_LookAndFeel = javax.swing.UIManager.getLookAndFeel;
handles.original_Java_LookAndFeel = sprintf('%s',handles.original_Java_LookAndFeel);
handles.original_Java_LookAndFeel = split(handles.original_Java_LookAndFeel,' - ');
handles.original_Java_LookAndFeel = extractBefore(handles.original_Java_LookAndFeel{end},']');
handles.original_Java_LookAndFeel = ['[LookAndFeel] ',handles.original_Java_LookAndFeel];
% A = javax.swing.UIManager.getLookAndFeel;
% char(A.getClass) % 'class com.jgoodies.looks.plastic.Plastic3DLookAndFeel' Replace class by [LookAndFeel]
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes MP3 wait for user response (see UIRESUME)
% uiwait(handles.MP3_GUI);
% --- Outputs from this function are returned to the command line.
function varargout = MP3_OutputFcn(~, ~, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes when user attempts to close MP3_GUI.
function MP3_GUI_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to MP3_GUI (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~isfield(handles, 'database')
delete(hObject);
if ~isempty(findobj('type', 'figure', 'name', 'MP3 pipeline Manager'))
close((findobj('type', 'figure', 'name', 'MP3 pipeline Manager')));
end
return
else
DBFilename = [handles.database.Properties.UserData.MP3_data_path, handles.database.Properties.UserData.db_filename];
SavedDB = load(DBFilename, 'database');
Diff = setdiff(SavedDB.database, handles.database);
if isempty(Diff)
delete(hObject);
if ~isempty(findobj('type', 'figure', 'name', 'MP3 pipeline Manager'))
close((findobj('type', 'figure', 'name', 'MP3 pipeline Manager')));
end
return
end
end
% Hint: delete(hObject) closes the figure
selection = questdlg('Before leaving, do you want to save your database?',...
'Warning',...
'Yes','No','Yes');
if isempty(selection)
return
end
switch selection
case 'Yes'
MP3_menu_save_database_Callback(hObject, eventdata, handles)
end
if ~isempty(findobj('type', 'figure', 'name', 'MP3 pipeline Manager'))
close((findobj('type', 'figure', 'name', 'MP3 pipeline Manager')));
end
delete(hObject);
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over MP3_slider_slice.
function MP3_slider_slice_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to MP3_slider_slice (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject);
if ~isfield(handles, 'data_loaded') && ~isfield(handles, 'data_selected_for_PRM')
return
end
Slice_min = get(hObject,'Min');
Slice_max = get(hObject,'Max');
Position = get(hObject,'Position');
SliderBarWidth = Position(3)/Slice_max;
set(hObject,'UserData',[Slice_min Slice_max SliderBarWidth]);
cp = get(handles.MP3_GUI,'CurrentPoint');
newValue = round((cp(1,1))/SliderBarWidth);
if newValue == get(handles.MP3_slider_slice,'Value')
return
elseif newValue > Slice_max
newValue = Slice_max;
elseif newValue < Slice_min
newValue = Slice_min;
end
set(handles.MP3_slider_slice,'Value',newValue);
MP3_update_axes(hObject, eventdata, handles)
%
% set(handles.MP3_GUI,'WindowButtonMotionFcn',{@MP3_slider_on_move,handles})
% set(handles.MP3_GUI,'WindowButtonUpFcn',{@MP3_slider_release_click,handles})
% --- Executes during object creation, after setting all properties.
function MP3_slider_slice_CreateFcn(hObject, ~, ~)
% hObject handle to MP3_slider_slice (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on selection change in MP3_name_list.
function MP3_name_list_Callback(hObject, eventdata, ~)
% hObject handle to MP3_name_list (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns MP3_name_list contents as cell array
% contents{get(hObject,'Value')} returns selected item from MP3_name_list
handles = guidata(hObject);
if ~isfield(handles, 'database')
return
end
set(handles.MP3_time_points_list, 'Value', 1);
set(handles.MP3_scans_list, 'Value', 1);
set(handles.MP3_file_list, 'Value', 1);
MP3_update_database_display(hObject, eventdata, handles);
% --- Executes during object creation, after setting all properties.
function MP3_name_list_CreateFcn(hObject, ~, ~)
% hObject handle to MP3_name_list (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in MP3_scans_list.
function MP3_scans_list_Callback(hObject, eventdata, handles)
% hObject handle to MP3_scans_list (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns MP3_scans_list contents as cell array
% contents{get(hObject,'Value')} returns selected item from MP3_scans_list
if ~isfield(handles, 'database')
return
end
if numel(get(handles.MP3_name_list, 'Value')) >1 || numel(get(handles.MP3_time_points_list, 'Value')) > 1
return
end
set(handles.MP3_file_list, 'Value', 1);
guidata(hObject, handles);
MP3_update_database_display(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function MP3_scans_list_CreateFcn(hObject, ~, ~) %#ok<*DEFNU>
% hObject handle to MP3_scans_list (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function MP3_update_database_display(hObject, eventdata, handles)
% handles = guidata(gcf, findobj('Tag', 'MP3_GUI'));
handles = guidata(handles.MP3_GUI);
if ~isfield(handles, 'database')
return
end
if isempty(handles.database)
% if the table is empty, clear all lists
set(handles.MP3_name_list, 'String', '', 'Value', 1);
set(handles.MP3_time_points_list, 'String', '', 'Value', 1);
set(handles.MP3_scans_list, 'String', '', 'Value', 1);
set(handles.MP3_file_list, 'String', '', 'Value', 1);
return
end
patient_id = get(handles.MP3_name_list, 'Value');
id_listing = unique(handles.database.Patient,'stable');
set(handles.MP3_name_list, 'String', char(id_listing));
if numel(patient_id)~= 1
return
end
Patient_filter = handles.database.Patient== id_listing(patient_id);
tp_listing = unique(handles.database.Tp(Patient_filter),'stable');
% check if the new time point listing is not shorter than the old one. If
% so update MP3_time_points_list 'Value'
if numel(tp_listing) < get(handles.MP3_time_points_list, 'Value')
set(handles.MP3_time_points_list, 'String', char(tp_listing), 'Value', numel(tp_listing));
else
set(handles.MP3_time_points_list, 'String', char(tp_listing));
end
time_point = get(handles.MP3_time_points_list, 'Value');
if get(handles.MP3_scan_VOIs_button, 'Value') == 0 %display parameters list
is_scan = handles.database.Type == 'Scan';
tp_filter = handles.database.Tp== tp_listing(time_point);
sequence_listing = handles.database.SequenceName(Patient_filter & tp_filter & is_scan);
% check if the sequence listing is not shorter than the old one. If
% so update MP3_scans_list 'Value'
if numel(sequence_listing) < get(handles.MP3_scans_list, 'Value')
set(handles.MP3_scans_list, 'String', char(sequence_listing), 'Value', numel(sequence_listing));
else
set(handles.MP3_scans_list, 'String', char(sequence_listing));
end
scan = get(handles.MP3_scans_list, 'Value');
file_text= cell(1, numel(sequence_listing(scan)));
for i=1:numel(sequence_listing(scan))
sequence_filter = handles.database.SequenceName== sequence_listing(scan(i));
file_text(i) = cellstr(handles.database.Filename(Patient_filter & tp_filter & sequence_filter & is_scan));
end
set(handles.MP3_file_list, 'String', file_text);
else %display VOIs list
%is_ROI= handles.database.Type == 'ROI';
is_ROI = handles.database.Type == 'ROI' | handles.database.Type == 'Cluster';
tp_filter = handles.database.Tp== tp_listing(time_point);
sequence_listing = handles.database.SequenceName(Patient_filter & tp_filter & is_ROI);
if isempty(sequence_listing)
set(handles.MP3_scans_list, 'String', '');
return
end
scan = get(handles.MP3_scans_list, 'Value');
set(handles.MP3_scans_list, 'String', char(sequence_listing));
file_text= cell(1, numel(sequence_listing(scan)));
for i=1:numel(sequence_listing(scan))
sequence_filter = handles.database.SequenceName== sequence_listing(scan(i));
if sum(Patient_filter & tp_filter & sequence_filter & is_ROI) == 1
file_text(i) = cellstr(handles.database.Filename(Patient_filter & tp_filter & sequence_filter & is_ROI));
else
% in case there are more than two entries in the database --> delete the extra one(s)
indexes = find(Patient_filter & tp_filter & sequence_filter & is_ROI);
handles.database(indexes(2:end),:)=[];
guidata(hObject, handles)
return
end
end
set(handles.MP3_file_list, 'String', file_text);
end
% Update the groupname
MP3_show_group_Callback(hObject, eventdata, handles)
% if the pipeline Manager is open, update the information : patient selected
% update the 'String' of MP3_pipeline_pushMP3Selection and MP3_pipeline_pushMP3TPSelection push button
if ~isempty(findobj('type', 'figure', 'name', 'MP3 pipeline Manager'))
% Get the hObject of MP3_pipeline
h = findobj('Tag', 'MP3_pipeline_manager_GUI');
% Get the handles of MP3_pipeline
data = guidata(h);
% Update the handles of MP3_pipeline by stocking the latest version of
% MP3 handles.
data.MP3_data = handles;
% Don't touch the original eventdata, just in case.
eventdata2 = eventdata;
%Update the MP3_pipeline tmp_database
[h, ~, data] = MP3_pipeline('UpdateTmpDatabase', h, eventdata2, data);
[~, ~, data] = MP3_pipeline('MP3_pipeline_UpdateTables', h, eventdata2, data);
clear('eventdata2')
guidata(h, data)
end
if ~isempty(findobj('Tag', 'MP3_pipeline_pushMP3Selection'))
data_selected = finddata_selected(handles);
if size(char(handles.database.Patient(data_selected)),1) > 1
return
else
set(findobj('Tag', 'MP3_pipeline_pushMP3Selection'), 'String', [char(handles.database.Patient(data_selected(1))) '-' char(handles.database.Tp(data_selected(1))) ' only'])
set(findobj('Tag', 'MP3_pipeline_pushMP3TPSelection'), 'String', ['All time point of :' char(handles.database.Patient(data_selected(1)))])
end
end
% --- Executes on selection change in MP3_time_points_list.
function MP3_time_points_list_Callback(hObject, eventdata, handles)
% hObject handle to MP3_time_points_list (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns MP3_time_points_list contents as cell array
% contents{get(hObject,'Value')} returns selected item from MP3_time_points_list
if ~isfield(handles, 'database')
return
end
set(handles.MP3_scans_list, 'Value', 1);
set(handles.MP3_file_list, 'Value', 1);
guidata(hObject, handles);
if numel(get(handles.MP3_time_points_list, 'Value')) >1 ||...
numel(get(handles.MP3_name_list, 'Value')) >1
else
MP3_update_database_display(hObject, eventdata, handles)
end
% --- Executes during object creation, after setting all properties.
function MP3_time_points_list_CreateFcn(hObject, ~, ~)
% hObject handle to MP3_time_points_list (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in MP3_scan_VOIs_button.
function MP3_scan_VOIs_button_Callback(hObject, eventdata, ~)
% hObject handle to MP3_scan_VOIs_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of MP3_scan_VOIs_button
handles = guidata(hObject);
if ~isfield(handles, 'database')
return
end
patient = get(handles.MP3_name_list, 'Value');
timepoint = get(handles.MP3_time_points_list, 'Value');
if numel(patient) > 1 || numel(timepoint) >1
warndlg('Please select only 1 patient before hitting this button','Warning');
set(handles.MP3_scan_VOIs_button, 'Value', 0)
return
end
value = get(handles.MP3_scan_VOIs_button, 'Value');
set(handles.MP3_scans_list, 'Value', 1);
if value == 0
set(handles.MP3_scan_VOIs_button, 'String', 'Scans');
else
set(handles.MP3_scan_VOIs_button, 'String', 'VOIs');
end
MP3_update_database_display(hObject, eventdata, handles);
% --- Executes on selection change in MP3_file_list.
function MP3_file_list_Callback(~, ~, ~)
% hObject handle to MP3_file_list (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns MP3_file_list contents as cell array
% contents{get(hObject,'Value')} returns selected item from MP3_file_list
% --- Executes during object creation, after setting all properties.
function MP3_file_list_CreateFcn(hObject, ~, ~)
% hObject handle to MP3_file_list (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --------------------------------------------------------------------
function MP3_rename_name_Callback(hObject, eventdata, handles)
% hObject handle to MP3_rename_name (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~isfield(handles, 'database')
return
end
data_selected = finddata_selected(handles);
if numel(data_selected) >1
warndlg('Please select only one Patient', 'Warning');
return
end
name_option = [cellstr(unique(handles.database.Patient(handles.database.Type == 'Scan')))' 'Other']';
[new_Patient_name, ok1] = listdlg('PromptString','Select the new scan name:',...
'Name', 'Select a Name',...
'SelectionMode','single',...
'ListSize', [400 300],...
'ListString',name_option);
if ok1 == 0
return
end
if strcmp('Other',name_option(new_Patient_name)) == 1
NewPatient = inputdlg('Name of the new Scan ', 'Question?', 1, {''});
else
NewPatient =name_option(new_Patient_name);
end
%% update the database with the new name
% but first check if the new scan name does not exist for this patient and
% time point
if find(handles.database.Patient == handles.database.Patient(data_selected) &...
handles.database.Tp == handles.database.Tp(data_selected) & ...
handles.database.SequenceName == NewPatient) > 0
msgbox('A Scan with the same name already exist for this patient at this time point') ;
return
end
idx_scan_to_rename = find(handles.database.Patient == handles.database.Patient(data_selected));
for i=1:numel(idx_scan_to_rename)
new_nii_filename = strrep(cellstr(handles.database.Filename(idx_scan_to_rename(i))), cellstr(handles.database.Patient(idx_scan_to_rename(i))), NewPatient);
% rename the scan file
if exist(fullfilename(handles, idx_scan_to_rename(i), '.nii'), 'file') == 0
warning_text = sprintf('##$ This file no not exist\n##$ %s',...
fullfilename(handles, idx_scan_to_rename(i), '.nii'));
msgbox(warning_text, 'rename file warning') ;
elseif exist(string(strcat(cellstr(handles.database.Path(idx_scan_to_rename(i))),new_nii_filename{:},'.nii')), 'file') == 2
msgbox('The new .nii file exist already!!') ;
else
movefile(fullfilename(handles, idx_scan_to_rename(i), '.nii'), strcat(char(handles.database.Path(idx_scan_to_rename(i))),new_nii_filename{:},'.nii'), 'f')
if exist(fullfilename(handles, idx_scan_to_rename(i), '.json'), 'file') == 2
movefile(fullfilename(handles, idx_scan_to_rename(i), '.json'), strcat(char(handles.database.Path(idx_scan_to_rename(i))),new_nii_filename{:},'.json'), 'f');
end
end
% update the Filename field in the table
handles.database.Patient(idx_scan_to_rename(i)) = NewPatient;
handles.database.Filename(idx_scan_to_rename(i)) = new_nii_filename;
end
% save the structure
guidata(hObject, handles);
set(handles.MP3_name_list, 'Value', 1);
% update graph and display
MP3_update_database_display(hObject, eventdata, handles);
% Save database
MP3_menu_save_database_Callback(hObject, eventdata, handles)
function MP3_remove_name_Callback(hObject, eventdata, handles)
% hObject handle to MP3_remove_name (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~isfield(handles, 'database')
return
end
%data_selected = finddata_selected(handles);
patient_seleted = get(handles.MP3_name_list, 'String');
patient_name = patient_seleted(get(handles.MP3_name_list, 'Value'),:);
%patient_name = unique(handles.database.Patient(data_selected));
user_response = questdlg(['Do you want to delete every data of ' cellstr(patient_name)']', 'Warning', 'Yes', 'No', 'Cancel', 'Cancel');
if strcmp(user_response, 'Cancel') || strcmp(user_response, 'No') || isempty(user_response)
return
end
nii_index = [];
for i=1:size(patient_name,1)
nii_index = [nii_index' find(handles.database.Patient == categorical(cellstr(patient_name(i,:))))']';
end
MP3_remove_scan(hObject, eventdata, handles, nii_index)
% --------------------------------------------------------------------
function MP3_name_right_click_Callback(hObject, eventdata, handles)
% hObject handle to MP3_name_right_click (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~isfield(handles, 'database')
return
end
% patient_num = get(handles.MP3_name_list, 'Value');
% omit_obj = findobj(handles.MP3_name_right_click, 'Label', 'Omit');
% set(omit_obj, 'Checked', 'off');
% if numel(patient_num) ==1 && ~isempty(handles.database(patient_num).group)
% group_name = handles.database(patient_num).group;
% if handles.database(patient_num).omit == 1
% set(omit_obj, 'Checked', 'on');
% end
% end
%
% show_menu_obj = findobj(handles.MP3_name_right_click, 'Label', 'Show');
% delete(get(show_menu_obj, 'Children')) %remove the 'old' show menu
%
% group = reshape({handles.database.group},1,[]);
% group_list = unique(group);
% %group_list = unique(group(1:2:end));
%
% if ~isfield(handles, 'database_all') || numel(handles.database_all) == numel(handles.database)
% for i = 1:numel(group_list)
% uimenu(show_menu_obj, 'Label', group_list{i},...
% 'Callback', @(hObject,eventdata)MP3('MP3_show_group_submenu',hObject,eventdata,guidata(hObject)));
% end
% else
% uimenu(show_menu_obj, 'Label', 'all',...
% 'Callback', @(hObject,eventdata)MP3('MP3_show_group_submenu',hObject,eventdata,guidata(hObject)));
% end
% guidata(hObject, handles);
%
% function MP3_show_group_submenu(hObject, eventdata, handles)
%
% show = get(hObject, 'Label');
% if strcmp('all', show)
% database_tmp = handles.database_all;
% for i = 1:numel(handles.database)
% name_size = numel(handles.database(i).name);
% match_name = find(strncmp(handles.database(i).name, {database_tmp.name}', name_size) ==1);
% if numel(match_name) >1
% for j =1:numel(match_name)
% if numel(handles.database(match_name(j)).name) == name_size;
% tmp = match_name(j);
% end
% end
% match_name = tmp;
% end
% database_tmp(match_name) = handles.database(i);
% end
% handles.database = database_tmp;
% handles= rmfield(handles, 'database_all');
% else
% n = 1;
% for i=1:numel(handles.database)
% if strncmp(show, handles.database(i).group, numel(show)) == 1 &&...
% numel(show) == numel(handles.database(i).group)
% database_tmp(n) = handles.database(i);
% n=n+1;
% end
% end
% handles.database_all = handles.database;
% handles.database = database_tmp;
% end
% set(handles.MP3_name_list, 'Value', 1);
% set(handles.MP3_time_points_list, 'Value', 1);
% guidata(handles.MP3_GUI, handles);
% MP3_update_database_display(hObject, eventdata, handles);
% --------------------------------------------------------------------
function MP3_open_database_ClickedCallback(hObject, eventdata, handles)
% hObject handle to MP3_open_database (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isfield(handles, 'database')
selection = questdlg('Have you saved the present database?',...
'Warning',...
'Yes','No','Yes');
switch selection
case 'No'
return
end
end
path_root=pwd;
%[filename, pathname]=uigetfile('*.mat','Open Mat File','MultiSelect','off');
selpath = uigetdir(path_root,'Select the project''s folder you want to open');
pathname = selpath;
%listfiles = what(selpath)
filename = 'MP3_database.mat';
if pathname == 0
return
else
if exist(fullfile(pathname, filename)) ~= 2
% The former name of MP3 is MIA. The following lines allow to open
% old projects with the new software.
if exist(fullfile(pathname, 'MIA_database.mat')) ~= 2
errordlg('The folder you selected might be corrupt. Please select a folder containing a MP3_database.mat file.', 'Cannot open project');
return
else
movefile(fullfile(pathname, 'MIA_database.mat'), fullfile(pathname, filename));
end
end
cd(pathname);
if ~strcmp(class(filename),'double') %#ok<STISA>
%reset everything
handles = MP3_clear_data(hObject, eventdata, handles);
set(handles.MP3_name_list, 'Value', 1);
set(handles.MP3_time_points_list, 'Value', 1);
set(handles.MP3_scan_VOIs_button, 'Value', 0);
set(handles.MP3_scans_list, 'Value', 1);
database = load(filename);
handles.database = database.database;
set(handles.MP3_name_list, 'String', handles.database.Properties.UserData.db_filename)
% update database path (in case the directory has moved)
handles.database.Properties.UserData.db_filename = filename;
new_patient_directory = strcat(pathname, filesep);
handles.database.Properties.UserData.MP3_data_path = new_patient_directory;
handles.database.Properties.UserData.MP3_Raw_data_path = [new_patient_directory, 'Raw_data', filesep];
handles.database.Properties.UserData.MP3_ROI_path = [new_patient_directory, 'ROI_data', filesep];
handles.database.Properties.UserData.MP3_Derived_data_path = [new_patient_directory, 'Derived_data', filesep];
handles.database.Properties.UserData.PSOM_path = [new_patient_directory, 'PSOM', filesep];
% update the path in the table
%handles.database.Path(handles.database.Type == 'Scan') = handles.database.Properties.UserData.MP3_Raw_data_path;
handles.database.Path(handles.database.IsRaw == '0' & handles.database.Type == 'Scan',:) = handles.database.Properties.UserData.MP3_Derived_data_path ;
handles.database.Path(handles.database.IsRaw == '1' & handles.database.Type == 'Scan',:) = handles.database.Properties.UserData.MP3_Raw_data_path;
handles.database.Path(handles.database.Type == 'ROI') = handles.database.Properties.UserData.MP3_ROI_path;
handles.database.Path(handles.database.Type == 'Cluster') = handles.database.Properties.UserData.MP3_ROI_path;
guidata(hObject, handles);
end
cd(path_root);
end
MP3_update_figureName(hObject, eventdata, handles)
guidata(hObject, handles);
MP3_update_database_display(hObject, eventdata, handles);
% --------------------------------------------------------------------
function MP3_time_points_right_click_Callback(~, ~, ~)
% hObject handle to MP3_time_points_right_click (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function MP3_rename_time_point_Callback(hObject, eventdata,handles)
% hObject handle to MP3_rename_time_point (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~isfield(handles, 'database')
return
end
data_selected = finddata_selected(handles);
if numel(data_selected) >1
warndlg('Please select only one Time point', 'Warning');
return
end
name_option = [cellstr(unique(handles.database.Tp(handles.database.Type == 'Scan')))' 'Other']';
[new_TP_name, ok1] = listdlg('PromptString','Select the new scan name:',...
'Name', 'Select a Name',...
'SelectionMode','single',...
'ListSize', [400 300],...
'ListString',name_option);
if ok1 == 0
return
end
if strcmp('Other',name_option(new_TP_name)) == 1
NewTp = inputdlg('Name of the new Scan ', 'Question?', 1, {''});
else
NewTp =name_option(new_TP_name);
end
%% update the database with the new name
% but first check if the new scan name does not exist for this patient and
% time point
% faire le ROI vs SCAN
if find(handles.database.Patient == handles.database.Patient(data_selected) &...
handles.database.Tp == handles.database.Tp(data_selected) & ...
handles.database.SequenceName == NewTp) > 0
msgbox('A Scan with the same name already exist for this patient at this time point') ;
return
end
idx_scan_to_rename = find(handles.database.Patient == handles.database.Patient(data_selected) & handles.database.Tp == handles.database.Tp(data_selected));
for i=1:numel(idx_scan_to_rename)
new_nii_filename = strrep(cellstr(handles.database.Filename(idx_scan_to_rename(i))), cellstr(handles.database.Tp(idx_scan_to_rename(i))), NewTp);
% rename the scan file
if exist(fullfilename(handles, idx_scan_to_rename(i), '.nii'), 'file') == 0
warning_text = sprintf('##$ This file no not exist\n##$ %s',...
fullfilename(handles, idx_scan_to_rename(i), '.nii'));
msgbox(warning_text, 'rename file warning') ;
elseif exist(string(strcat(cellstr(handles.database.Path(idx_scan_to_rename(i))),new_nii_filename{:},'.nii')), 'file') == 2
msgbox('The new .nii file exist already!!') ;
else
movefile(fullfilename(handles, idx_scan_to_rename(i), '.nii'), strcat(char(handles.database.Path(idx_scan_to_rename(i))),new_nii_filename{:},'.nii'), 'f')
if exist(fullfilename(handles, idx_scan_to_rename(i), '.json'), 'file') == 2
movefile(fullfilename(handles, idx_scan_to_rename(i), '.json'), strcat(char(handles.database.Path(idx_scan_to_rename(i))),new_nii_filename{:},'.json'), 'f');
end
end
% update the Filename field in the table
handles.database.Tp(idx_scan_to_rename(i)) = NewTp;
handles.database.Filename(idx_scan_to_rename(i)) = new_nii_filename;
end
% save the structure
guidata(hObject, handles);
%% update graph and display
MP3_update_database_display(hObject, eventdata, handles);
% save database
MP3_menu_save_database_Callback(hObject, eventdata, handles)
% --------------------------------------------------------------------
function MP3_rename_scan_Callback(hObject, eventdata, handles)
% hObject handle to MP3_rename_scan (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~isfield(handles, 'database')
return
end
data_selected = finddata_selected(handles);
if numel(data_selected) >1
warndlg('Please select only one scan', 'Warning');
return
end
if get(handles.MP3_scan_VOIs_button, 'Value')
name_option = [cellstr(unique(handles.database.SequenceName(handles.database.Type == 'ROI')))' 'Other']';
else
name_option = [cellstr(unique(handles.database.SequenceName(handles.database.Type == 'Scan')))' 'Other']';
end
[new_scan_name, ok1] = listdlg('PromptString','Select the new scan name:',...
'Name', 'Select a Name',...
'SelectionMode','single',...
'ListSize', [400 300],...
'ListString',name_option);
if ok1 == 0
return
end
if strcmp('Other',name_option(new_scan_name)) == 1
newparameter = inputdlg('Name of the new Scan ', 'Question?', 1, {''});
else
newparameter =name_option(new_scan_name);
end
%% update the database with the new name
% but first check if the new scan name does not exist for this patient and
% time point
% faire le ROI vs SCAN
if find(handles.database.Patient == handles.database.Patient(data_selected) &...
handles.database.Tp == handles.database.Tp(data_selected) & ...
handles.database.SequenceName == newparameter) > 0
msgbox('A Scan with the same name already exist for this patient at this time point') ;
return
end
new_nii_filename = strrep(cellstr(handles.database.Filename(data_selected)), cellstr(handles.database.SequenceName(data_selected)), newparameter);
% rename the scan file
if exist(fullfilename(handles, data_selected, '.nii'), 'file') == 0
warning_text = sprintf('##$ This file no not exist\n##$ %s',...
fullfilename(handles, data_selected, '.nii'));
msgbox(warning_text, 'rename file warning') ;
elseif exist(string(strcat(cellstr(handles.database.Path(data_selected)),new_nii_filename{:},'.nii')), 'file') == 2
msgbox('The new .nii file exist already!!') ;
else
movefile(fullfilename(handles, data_selected, '.nii'), strcat(char(handles.database.Path(data_selected)),new_nii_filename{:},'.nii'), 'f')
% rename json file if needed
if exist(fullfilename(handles, data_selected, '.json'), 'file') == 2
movefile(fullfilename(handles, data_selected, '.json'), strcat(char(handles.database.Path(data_selected)),new_nii_filename{:},'.json'), 'f');
end
% rename mat file if needed
if exist(fullfilename(handles, data_selected, '.mat'), 'file') == 2
movefile(fullfilename(handles, data_selected, '.mat'), strcat(char(handles.database.Path(data_selected)),new_nii_filename{:},'.mat'), 'f');
end
end
% update the Filename field in the table
handles.database.SequenceName(data_selected) = newparameter;
handles.database.Filename(data_selected) = new_nii_filename;
% save the structure
guidata(hObject, handles);
%% update graph and display
MP3_update_database_display(hObject, eventdata, handles);
% Save database
MP3_menu_save_database_Callback(hObject, eventdata, handles)
% --------------------------------------------------------------------
function MP3_remove_scan_Callback(hObject, eventdata, handles)
% hObject handle to MP3_remove_scan (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~isfield(handles, 'database')
return
end
nii_index = finddata_selected(handles);
user_response = questdlg('Do you want to delete these data ??', 'Warning', 'Yes', 'No', 'Cancel', 'Cancel');
if strcmp(user_response, 'Cancel') || strcmp(user_response, 'No') || isempty(user_response)
return
end
MP3_remove_scan(hObject, eventdata, handles, nii_index)
% --------------------------------------------------------------------
function MP3_remove_time_point_Callback(hObject, eventdata, handles)
% hObject handle to MP3_remove_time_point (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~isfield(handles, 'database')
return
end
data_selected = finddata_selected(handles);
Time_point_selected = unique(handles.database.Tp(data_selected));
patient_selected = unique(handles.database.Patient(data_selected));
user_response = questdlg(['Do you want to delete every data of ' char(Time_point_selected) '??'], 'Warning', 'Yes', 'No', 'Cancel', 'Cancel');
if strcmp(user_response, 'Cancel') || strcmp(user_response, 'No')
return
end
nii_index = find(handles.database.Patient == patient_selected & handles.database.Tp == Time_point_selected);
MP3_remove_scan(hObject, eventdata, handles, nii_index)
% --------------------------------------------------------------------
function MP3_ScanVoi_right_click_Callback(~, ~, ~)
% hObject handle to MP3_ScanVoi_right_click (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function MP3_update_figureName(~, ~, handles)
num_timepoint = 0;
patient_listing = unique(handles.database.Patient);
for i=1:numel(patient_listing)
num_timepoint = num_timepoint+ numel(unique(handles.database.Tp(handles.database.Patient == patient_listing(i))));
end
Name_soft = 'Medical software for Processing multi-Parametric image Pipelines (Grenoble Institute of neurosciences - France)';
Spl = strsplit(handles.database.Properties.UserData.MP3_data_path, filesep);
Name_Projet = Spl{end-1};
%old_title = get(handles.MP3_GUI, 'Name');
title = [Name_soft, ' ; Projet : ', Name_Projet, ' ; ', num2str(numel(patient_listing)),...
' patients and ', num2str(num_timepoint), ' ','time points'];
set(handles.MP3_GUI, 'Name', title);