0001 function varargout = modifyConstValuesGUI(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 gui_Singleton = 1;
0027 gui_State = struct('gui_Name',mfilename, ...
0028 'gui_Singleton', gui_Singleton, ...
0029 'gui_OpeningFcn', @modifyConstValuesGUI_OpeningFcn, ...
0030 'gui_OutputFcn', @modifyConstValuesGUI_OutputFcn, ...
0031 'gui_LayoutFcn', [] , ...
0032 'gui_Callback', []);
0033 if nargin && ischar(varargin{1})
0034 gui_State.gui_Callback = str2func(varargin{1});
0035 end
0036
0037 if nargout
0038 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0039 else
0040 gui_mainfcn(gui_State, varargin{:});
0041 end
0042
0043
0044
0045 function modifyConstValuesGUI_OpeningFcn(hObject, eventdata, handles, varargin)
0046
0047
0048
0049
0050
0051 global settings_mod;
0052
0053 handles.output = hObject;
0054 set(handles.figure1, 'units', 'normalized', 'position', [0.1 0.1 0.8 0.8])
0055 load_listbox(handles)
0056 handles.directory.String = 'Image filename';
0057 handles.display_flag = 3;
0058 settings_mod.data = [];
0059 settings_mod.phaseImage = [];
0060 settings_mod.axisFlag = 0;
0061 settings_mod.loadDirectory = [];
0062
0063
0064 handles.seg_radio.Value = 1;
0065 initialize_all(handles)
0066
0067 guidata(hObject, handles);
0068 settings_mod.handles = handles;
0069 updateUI(handles);
0070
0071
0072
0073
0074
0075
0076 function varargout = modifyConstValuesGUI_OutputFcn(hObject, eventdata, handles)
0077
0078
0079
0080
0081
0082 varargout{1} = handles.output;
0083
0084
0085
0086
0087 function try_const_Callback(hObject, eventdata, handles)
0088
0089
0090
0091
0092 dirname = (handles.directory.String);
0093 if ~strcmp(dirname(end-3:end), '.tif')
0094 errordlg('Please select an image');
0095 end
0096 tryDifferentConstants(dirname, []);
0097
0098 function load_listbox(handles)
0099 [~,resFlags] = getConstantsList();
0100 [sorted_names,sorted_index] = sortrows(resFlags');
0101 handles.file_names = sorted_names;
0102 handles.sorted_index = sorted_index;
0103 set(handles.constants_list,'String',handles.file_names,'Value',1)
0104
0105
0106 function constants_list_Callback(hObject, eventdata, handles)
0107
0108
0109
0110
0111
0112
0113 getValuesFromConst(handles)
0114
0115 function getValuesFromConst(handles)
0116 global settings_mod;
0117 resValue = get(handles.constants_list,'Value');
0118 res = handles.constants_list.String{resValue};
0119 CONST = loadConstants (res,0,0);
0120 handles.cut_intensity.Value = CONST.superSeggerOpti.CUT_INT;
0121 handles.max_wid.Value = CONST.superSeggerOpti.MAX_WIDTH ;
0122 handles.mask_th2.Value = CONST.superSeggerOpti.THRESH2;
0123 handles.mask_th1.Value = CONST.superSeggerOpti.THRESH1 ;
0124 handles.magic_thresh.Value = CONST.superSeggerOpti.MAGIC_THRESHOLD;
0125 handles.magic_radius.Value = CONST.superSeggerOpti.MAGIC_RADIUS ;
0126 handles.maxLengRegOpti.String = CONST.regionOpti.MIN_LENGTH ;
0127 handles.gaus_wid.Value = CONST.superSeggerOpti.SMOOTH_WIDTH;
0128 update_text_values (handles)
0129 settings_mod.CONST = CONST;
0130
0131
0132 function putValuesInConstants(handles)
0133 global settings_mod
0134 resValue = get(handles.constants_list,'Value');
0135 res = handles.constants_list.String{resValue};
0136 CONST = loadConstants (res,0,0);
0137 CONST.superSeggerOpti.CUT_INT = handles.cut_intensity.Value;
0138 CONST.superSeggerOpti.MAX_WIDTH = handles.max_wid.Value;
0139 CONST.superSeggerOpti.THRESH2 = handles.mask_th2.Value;
0140 CONST.superSeggerOpti.THRESH1 = handles.mask_th1.Value;
0141 CONST.superSeggerOpti.MAGIC_THRESHOLD = handles.magic_thresh.Value;
0142 CONST.superSeggerOpti.MAGIC_RADIUS = handles.magic_radius.Value;
0143 CONST.regionOpti.MIN_LENGTH = handles.maxLengRegOpti.Value;
0144 CONST.superSeggerOpti.SMOOTH_WIDTH = handles.gaus_wid.Value;
0145 settings_mod.CONST = CONST;
0146
0147
0148 function constants_list_CreateFcn(hObject, eventdata, handles)
0149
0150
0151
0152
0153
0154
0155 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0156 set(hObject,'BackgroundColor','white');
0157 end
0158
0159
0160 function directory_Callback(hObject, eventdata, handles)
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170 function directory_CreateFcn(hObject, eventdata, handles)
0171
0172
0173
0174
0175
0176
0177 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0178 set(hObject,'BackgroundColor','white');
0179 end
0180
0181
0182
0183 function save_Callback(hObject, eventdata, handles)
0184
0185
0186
0187 global settings_mod;
0188 putValuesInConstants(handles)
0189 CONST = settings_mod.CONST;
0190 [FileName,PathName,~] = uiputfile('newConstantsName.mat');
0191 if FileName~=0
0192 save([PathName,FileName], '-struct', 'CONST');
0193 end
0194
0195
0196
0197
0198 function constants_list_ButtonDownFcn(hObject, eventdata, handles)
0199
0200
0201
0202
0203
0204
0205 function image_folder_ClickedCallback(hObject, eventdata, handles)
0206
0207
0208
0209 [imageName,directoryName , ~] = uigetfile('*.tif', 'Pick an image file');
0210 if imageName~=0
0211 handles.directory.String = [directoryName,filesep,imageName];
0212 settings_mod.phaseImage = imread(handles.directory.String);
0213 axes(handles.viewport_modify);
0214 imshow(settings_mod.phaseImage,[]);
0215 end
0216
0217
0218 function updateUI(handles)
0219 global settings_mod;
0220 if ~isempty(settings_mod.data)
0221 if handles.display_flag == 3
0222 showSegDataPhase(settings_mod.data, handles.viewport_modify);
0223 elseif handles.display_flag == 2
0224 axes(handles.viewport_modify);
0225 imshow(settings_mod.data.mask_bg,[])
0226 elseif handles.display_flag == 1
0227 axes(handles.viewport_modify);
0228 imshow(settings_mod.data.phase,[])
0229 end
0230 end
0231 if numel(handles.viewport_modify.Children) > 0
0232 set(handles.viewport_modify.Children(1),'ButtonDownFcn',@imageButtonDownFcn);
0233 hold on;
0234 end
0235
0236
0237 function slider3_Callback(hObject, eventdata, handles)
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247 function slider3_CreateFcn(hObject, eventdata, handles)
0248
0249
0250
0251
0252
0253 if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0254 set(hObject,'BackgroundColor',[.9 .9 .9]);
0255 end
0256
0257
0258
0259 function magic_thresh_Callback(hObject, eventdata, handles)
0260
0261
0262
0263
0264
0265
0266 val = hObject.Value;
0267 hObject.Value = round(val);
0268 handles.magic_val.String = num2str(hObject.Value);
0269
0270
0271
0272 function magic_thresh_CreateFcn(hObject, eventdata, handles)
0273
0274
0275
0276
0277
0278 if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0279 set(hObject,'BackgroundColor',[.9 .9 .9]);
0280 end
0281
0282
0283 function cut_intensity_Callback(hObject, eventdata, handles)
0284
0285
0286
0287
0288
0289
0290 val = hObject.Value;
0291 hObject.Value = round(val);
0292 handles.cut_int_text.String = num2str(handles.cut_intensity.Value);
0293
0294
0295 function cut_intensity_CreateFcn(hObject, eventdata, handles)
0296
0297
0298
0299
0300
0301 if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0302 set(hObject,'BackgroundColor',[.9 .9 .9]);
0303 end
0304
0305
0306
0307 function mask_th1_Callback(hObject, eventdata, handles)
0308
0309
0310
0311
0312
0313
0314 val = hObject.Value;
0315 hObject.Value = round(val);
0316 handles.mask_th1_text.String = num2str(hObject.Value);
0317
0318
0319 function mask_th1_CreateFcn(hObject, eventdata, handles)
0320
0321
0322
0323
0324 if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0325 set(hObject,'BackgroundColor',[.9 .9 .9]);
0326 end
0327
0328 function update_text_values (handles)
0329 handles.magic_val.String = num2str(handles.magic_thresh.Value);
0330 handles.magic_rad_text.String = num2str(handles.magic_radius.Value);
0331 handles.cut_int_text.String = num2str(handles.cut_intensity.Value);
0332 handles.mask_th1_text.String = num2str(handles.mask_th1.Value);
0333 handles.mask_th2_text.String = num2str(handles.mask_th2.Value);
0334 handles.max_wid_text.String = num2str(handles.max_wid.Value);
0335 handles.gaus_wid_text.String = num2str(handles.gaus_wid.Value);
0336
0337
0338 function mask_th2_Callback(hObject, eventdata, handles)
0339
0340
0341
0342
0343
0344
0345 val = hObject.Value;
0346 hObject.Value = round(val);
0347 handles.mask_th2_text.String = num2str(hObject.Value);
0348
0349
0350 function mask_th2_CreateFcn(hObject, eventdata, handles)
0351
0352
0353
0354
0355
0356 if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0357 set(hObject,'BackgroundColor',[.9 .9 .9]);
0358 end
0359
0360
0361 function magic_radius_Callback(hObject, eventdata, handles)
0362
0363
0364
0365
0366
0367
0368 val = round(hObject.Value);
0369 hObject.Value =val;
0370 handles.magic_rad_text.String = num2str(hObject.Value);
0371
0372
0373 function magic_radius_CreateFcn(hObject, eventdata, handles)
0374
0375
0376
0377
0378
0379 if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0380 set(hObject,'BackgroundColor',[.9 .9 .9]);
0381 end
0382
0383
0384
0385 function min_thresh_Callback(hObject, eventdata, handles)
0386
0387
0388
0389
0390
0391
0392 val = hObject.Value;
0393 hObject.Value = round(val);
0394 handles.min_thresh_text.String = num2str(hObject.Value);
0395
0396
0397
0398 function min_thresh_CreateFcn(hObject, eventdata, handles)
0399
0400
0401
0402
0403
0404 if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0405 set(hObject,'BackgroundColor',[.9 .9 .9]);
0406 end
0407
0408
0409
0410
0411 function max_thresh_CreateFcn(hObject, eventdata, handles)
0412
0413
0414
0415
0416
0417 if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0418 set(hObject,'BackgroundColor',[.9 .9 .9]);
0419 end
0420
0421
0422
0423 function max_wid_Callback(hObject, eventdata, handles)
0424
0425
0426
0427
0428
0429
0430 val = round(hObject.Value);
0431 hObject.Value=val;
0432 handles.max_wid_text.String = num2str(hObject.Value);
0433
0434
0435 function max_wid_CreateFcn(hObject, eventdata, handles)
0436
0437
0438
0439
0440
0441 if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0442 set(hObject,'BackgroundColor',[.9 .9 .9]);
0443 set(hObject,'Max',50,'Min',5)
0444 hObject.Value = get(hObject,'Min');
0445 handles.max_wid_text.String = num2str(hObject.Value);
0446 end
0447
0448
0449
0450
0451 function max_thresh_Callback(hObject, eventdata, handles)
0452
0453
0454
0455
0456
0457
0458 val = round(hObject.Value);
0459 hObject.Value=val;
0460 handles.max_thresh_text.String = num2str(hObject.Value);
0461 guidata(hObject,handles);
0462
0463
0464 function initialize_all (handles)
0465
0466 set(handles.magic_thresh,'Max',30,'Min',0)
0467 set(handles.magic_thresh,'SliderStep',[0.1 1])
0468
0469
0470 set(handles.magic_radius,'Max',15,'Min',0.1)
0471 set(handles.magic_radius,'SliderStep',[0.1 1])
0472
0473
0474 set(handles.cut_intensity,'Max',150,'Min',10)
0475 set(handles.cut_intensity,'SliderStep',[0.1 1])
0476
0477
0478 set(handles.gaus_wid,'Max',1,'Min',0.1)
0479 set(handles.gaus_wid,'SliderStep',[0.1 1])
0480
0481
0482 set(handles.mask_th1,'Max',100,'Min',10)
0483 set(handles.mask_th1,'SliderStep',[0.1 1])
0484
0485
0486 set(handles.mask_th2,'Max',100,'Min',0)
0487 set(handles.mask_th2,'SliderStep',[0.1 1])
0488
0489
0490 set(handles.max_wid,'Max',20,'Min',5)
0491 set(handles.max_wid,'SliderStep',[0.1 1])
0492
0493 getValuesFromConst(handles)
0494
0495
0496
0497 function run_Callback(hObject, eventdata, handles)
0498
0499
0500
0501
0502 global settings_mod;
0503 putValuesInConstants(handles)
0504 CONST = settings_mod.CONST;
0505 imageName = handles.directory.String;
0506 if numel(imageName)<3 || ~strcmp(imageName(end-3:end), '.tif')
0507 image_folder_ClickedCallback([],[],handles);
0508 end
0509 phaseIm = imread(handles.directory.String);
0510
0511 set(gcf,'Pointer','watch');
0512 settings_mod.data = superSeggerOpti(phaseIm,[],0,CONST);
0513
0514 guidata(hObject, handles);
0515 updateUI(handles);
0516 set(gcf,'Pointer','arrow');
0517
0518 function max_width_regOpt_Callback(hObject, eventdata, handles)
0519
0520
0521
0522
0523
0524
0525
0526
0527 function max_width_regOpt_CreateFcn(hObject, eventdata, handles)
0528
0529
0530
0531
0532
0533
0534 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0535 set(hObject,'BackgroundColor','white');
0536 end
0537
0538 function maxLengRegOpti_Callback(hObject, eventdata, handles)
0539
0540
0541
0542
0543
0544
0545
0546
0547 function maxLengRegOpti_CreateFcn(hObject, eventdata, handles)
0548
0549
0550
0551
0552
0553
0554 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0555 set(hObject,'BackgroundColor','white');
0556 end
0557
0558
0559 function imageButtonDownFcn(hObject, eventdata, handles)
0560
0561
0562
0563 global settings_mod;
0564 updateUI(settings_mod.handles);
0565 point = round(eventdata.IntersectionPoint(1:2));
0566 if isempty(settings_mod.data)
0567 errordlg('Press find segments first');
0568 end
0569 if ~isfield(settings_mod.data,'regs')
0570 settings_mod.data = intMakeRegs( settings_mod.data, settings_mod.CONST, [], [] );
0571 end
0572
0573 data = settings_mod.data;
0574 ss = size(data.phase);
0575 tmp = zeros([51,51]);
0576 tmp(26,26) = 1;
0577 tmp = 8000-double(bwdist(tmp));
0578 rmin = max([1,point(2)-25]);
0579 rmax = min([ss(1),point(2)+25]);
0580 cmin = max([1,point(1)-25]);
0581 cmax = min([ss(2),point(1)+25]);
0582 rrind = rmin:rmax;
0583 ccind = cmin:cmax;
0584 pointSize = [numel(rrind),numel(ccind)];
0585 tmp = tmp(26-point(2)+rrind,26-point(1)+ccind).*data.mask_cell(rrind,ccind);
0586 [~,ind] = max( tmp(:) );
0587
0588 [sub1, sub2] = ind2sub( pointSize, ind );
0589 ii = data.regs.regs_label(sub1-1+rmin,sub2-1+cmin);
0590 hold on;
0591 plot( sub2-1+cmin, sub1-1+rmin, 'o', 'MarkerFaceColor', 'g' );
0592
0593 if ii ~=0
0594 settings_mod.handles.width_length_image.String = (['length : ', num2str(data.regs.info(ii,1)), ...
0595 ' max width : ', num2str(data.regs.info(ii,4))]);
0596 else
0597 disp ('empty')
0598 end
0599
0600
0601
0602 function help_button_ClickedCallback(hObject, eventdata, handles)
0603
0604
0605
0606
0607 message = ({'SuperSeggerOpti - Modifying Constants Module'
0608 '------------------------------------------------------------'
0609 ' '
0610 'Hover over the names to get more information about the different variables. Choose a constant, change the slider''s values and click run to see the result. Save the constants in the settings_mod folder to use them immediately. '
0611 ' '
0612 });
0613
0614 msgbox(message,'HELP');
0615
0616
0617
0618 function phase_radio_Callback(hObject, eventdata, handles)
0619
0620
0621
0622 if get(hObject,'Value') == 1
0623 handles.display_flag = 1;
0624 handles.mask_radio.Value = 0;
0625 handles.seg_radio.Value = 0;
0626 end
0627 guidata(hObject, handles);
0628 updateUI(handles);
0629
0630
0631
0632
0633 function mask_radio_Callback(hObject, eventdata, handles)
0634
0635
0636
0637 if get(hObject,'Value') == 1
0638 handles.display_flag = 2;
0639 handles.seg_radio.Value = 0;
0640 handles.phase_radio.Value = 0;
0641 end
0642 guidata(hObject, handles);
0643 updateUI(handles);
0644
0645
0646
0647 function seg_radio_Callback(hObject, eventdata, handles)
0648
0649
0650
0651 if get(hObject,'Value') == 1
0652 handles.display_flag = 3;
0653 handles.mask_radio.Value = 0;
0654 handles.phase_radio.Value = 0;
0655 end
0656 guidata(hObject, handles);
0657 updateUI(handles);
0658
0659
0660
0661 function gaus_wid_Callback(hObject, eventdata, handles)
0662
0663
0664
0665
0666
0667
0668 handles.gaus_wid_text.String = num2str(hObject.Value);
0669
0670
0671
0672 function gaus_wid_CreateFcn(hObject, eventdata, handles)
0673
0674
0675
0676
0677
0678 if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0679 set(hObject,'BackgroundColor',[.9 .9 .9]);
0680 end