diff --git a/4_grains/GtThreshold.m b/4_grains/GtThreshold.m index 4bd2d5e3daa1a8ada53749511e8ef3e28b2e5e8a..bc279809d166453f044143eb3adddede6fdbda75 100644 --- a/4_grains/GtThreshold.m +++ b/4_grains/GtThreshold.m @@ -15,8 +15,7 @@ classdef GtThreshold < handle obj.conf = []; obj.conf.verbose = true; - obj.param = load('parameters.mat'); - obj.param = obj.param.parameters; + obj.param = gtLoadParameters(); par_thr = obj.getThrParams(); [par_thr, rej_params] = parse_pv_pairs(par_thr, varargin); @@ -234,10 +233,14 @@ classdef GtThreshold < handle fprintf('\b\b: Done.\n'); end - function seg_struct = volumeThreshold(obj, volume, threshold, seed) + function seg_struct = volumeThreshold(obj, volume, threshold, seed, do_region_prop) % GTTHRESHOLD/volumeThreshold % segvol = volumeThreshold(obj, volume, threshold, center) + if (~exist('do_region_prop', 'var')) + do_region_prop = true; + end + if (isempty(volume)) gtError('GtThreshold:wrong_argument', ... 'Volume to segment is empty!') @@ -253,7 +256,7 @@ classdef GtThreshold < handle end seg_struct = struct('vol', volume, 'shift', [0 0 0]); - seg_struct = obj.segmentAndDoMorph(seg_struct, threshold, do_morpho, seed); + seg_struct = obj.segmentAndDoMorph(seg_struct, threshold, do_morpho, seed, do_region_prop); end end @@ -456,9 +459,13 @@ classdef GtThreshold < handle grain_rec.id, count, delta) end - function grain_seg = segmentAndDoMorph(~, grain_rec, threshold, do_morpho, seed) + function grain_seg = segmentAndDoMorph(~, grain_rec, threshold, do_morpho, seed, do_region_prop) % GTTHRESHOLD/SEGMENTANDDOMORPH + if (~exist('do_region_prop', 'var')) + do_region_prop = true; + end + message = 'morphological reconstruction failed'; if (isfield(grain_rec, 'id')) message = [message ... @@ -481,26 +488,32 @@ classdef GtThreshold < handle seed = zeros(0, 3); end - regprop = regionprops(seg_vol, 'BoundingBox', 'Area'); - if (length(regprop) > 1) - % let's take the biggest! (usually happens without morpho) - ind = find([regprop.Area] == max([regprop.Area]), 1); - regprop = regprop(ind); - end + if (do_region_prop) + regprop = regionprops(seg_vol, 'BoundingBox', 'Area'); + if (length(regprop) > 1) + % let's take the biggest! (usually happens without morpho) + ind = find([regprop.Area] == max([regprop.Area]), 1); + regprop = regprop(ind); + end - if isempty(regprop) - grain_seg.seg = []; - grain_seg.Area = []; - grain_seg.segbb = []; + if isempty(regprop) + grain_seg.seg = []; + grain_seg.Area = []; + grain_seg.segbb = []; + else + seg_bb = regprop.BoundingBox([2 1 3 5 4 6]); + + % ceil because Matlab regionprops yields "0.5" (instead of 1) + % for bb start values + grain_seg.seg = gtCrop(seg_vol, ceil(seg_bb)); + grain_seg.Area = regprop.Area; + seg_bb(1:3) = grain_rec.shift + ceil(seg_bb(1:3)) - 1; + grain_seg.segbb = seg_bb; + end else - seg_bb = regprop.BoundingBox([2 1 3 5 4 6]); - - % ceil because Matlab regionprops yields "0.5" (instead of 1) - % for bb start values - grain_seg.seg = gtCrop(seg_vol, ceil(seg_bb)); - grain_seg.Area = regprop.Area; - seg_bb(1:3) = grain_rec.shift + ceil(seg_bb(1:3)) - 1; - grain_seg.segbb = seg_bb; + grain_seg.seg = seg_vol; + grain_seg.Area = []; + grain_seg.segbb = [0, 0, 0, size(seg_vol)]; end grain_seg.threshold = threshold; grain_seg.seed = seed; diff --git a/5_reconstruction/GtGuiMultiThresholdVolume.m b/5_reconstruction/GtGuiMultiThresholdVolume.m index f8bd5d9fda24dbc9e4124fad18aaf5f49c0f01ba..8d8abf2859d0ef97a45c6bc6aaacd9fd8bcdbbe7 100644 --- a/5_reconstruction/GtGuiMultiThresholdVolume.m +++ b/5_reconstruction/GtGuiMultiThresholdVolume.m @@ -14,11 +14,11 @@ classdef GtGuiMultiThresholdVolume < GtGuiThresholdGrain end function movedSlider(obj) - new_thresh = get(obj.conf.h_thr_slider(1), 'Value'); + new_thresh = get(obj.conf.h_thr_slider(1), 'Value') set(obj.conf.h_thr_edit, 'String', num2str(obj.threshold(1))); obj.setThresholds(new_thresh, 1); - new_thresh = get(obj.conf.h_thr_slider(2), 'Value'); + new_thresh = get(obj.conf.h_thr_slider(2), 'Value') set(obj.conf.h_thr_edit, 'String', num2str(obj.threshold(2))); obj.setThresholds(new_thresh, 2); @@ -103,19 +103,24 @@ classdef GtGuiMultiThresholdVolume < GtGuiThresholdGrain filter = {'*.mat', 'MATLAB Files (*.mat)'; '*.edf', 'EDF files (ESRF Data Format, *.edf)'}; [filename, pathname, filerIndex] = uiputfile(filter, 'Select file...', fullfile('5_reconstruction', 'volume_mask_multi.mat')); + if (isnumeric(filename) && filename == 0) + return; + end thr = GtThreshold(); vol = zeros(size(self.conf.vol), class(self.conf.vol)); fprintf('Applying thresholds: ') for ii = 1:numel(self.threshold) - num_chars = fprintf('%02d/%02d', ii, numel(self.threshold)); + num_chars = fprintf('%02d/%02d (thr: %g)', ii, numel(self.threshold), self.threshold(ii)); - partial_seg_struct = thr.volumeThreshold(self.conf.vol, self.threshold(ii)); + partial_seg_struct = thr.volumeThreshold(self.conf.vol, self.threshold(ii), [], false); - vol = gtPlaceSubVolume(vol, partial_seg_struct.vol, partial_seg_struct.segbb(1:3), ii); + vol = gtPlaceSubVolume(vol, single(partial_seg_struct.seg), partial_seg_struct.segbb(1:3), ii); fprintf(repmat('\b', [1, num_chars])); end + fprintf(repmat(' ', [1, num_chars])); + fprintf(repmat('\b', [1, num_chars])); fprintf('(%02d) Done.\n', numel(self.threshold)) if (filerIndex == 1)