|
58 | 58 | % extract max nodes. TODO: look into UGM decode methods.
|
59 | 59 | [~, maxNodes] = max(nodeBel, [], 2);
|
60 | 60 |
|
61 |
| - % create index in pDst - sized array |
62 |
| - qSel = sub2ind(size(pDst), (1:size(pDst, 1))', maxNodes(:)); |
| 61 | + |
| 62 | + |
| 63 | + % get indexes in pDst(NxK) of optimal solutions for each node. |
| 64 | + qSelIdx = sub2ind(size(pDst), (1:size(pDst, 1))', maxNodes(:)); |
| 65 | + |
| 66 | + % permute patches to be NxPxK --> PxNxK |
63 | 67 | permpatches = permute(patches, [2, 1, 3]); % each row is a voxel
|
64 |
| - qpatches = permpatches(:, qSel)'; % for each voxel, use the selection |
| 68 | + qpatches = permpatches(:, qSelIdx)'; % for each voxel, use the selection |
| 69 | + |
65 | 70 | pIdxSel = []; rIdxSel = [];
|
66 | 71 | if nargout >= 4 && ~isempty(inputs.pIdx)
|
67 |
| - pIdxSel = inputs.pIdx(qSel); |
68 |
| - rIdxSel = inputs.rIdx(qSel); |
| 72 | + pIdxSel = inputs.pIdx(qSelIdx); |
| 73 | + rIdxSel = inputs.rIdx(qSelIdx); |
69 | 74 | end
|
70 | 75 |
|
71 | 76 | % prepare outputs
|
72 | 77 | belstruct = structrich(nodeBel, edgeBel, logZ, maxNodes);
|
73 | 78 | potstruct = structrich(nodePot, edgePot, edgeStruct);
|
74 |
| - vargout = {belstruct, potstruct, qSel, pIdxSel, rIdxSel}; |
| 79 | + vargout = {belstruct, potstruct, qSelIdx, pIdxSel, rIdxSel}; |
75 | 80 | varargout = vargout(1:nargout);
|
76 | 81 | end
|
77 | 82 |
|
|
217 | 222 | p.addParameter('pIdx', [], @isnumeric);
|
218 | 223 | p.addParameter('rIdx', [], @isnumeric);
|
219 | 224 | p.addParameter('refgridsize', [], @(x) isnumeric(x) || iscell(x));
|
220 |
| - p.addParameter('gridIdx', 1:prod(gridSize), @isnumeric); |
| 225 | + p.addParameter('gridIdx', [], @isnumeric); |
221 | 226 | p.addParameter('srcSize', [], @isnumeric);
|
222 | 227 | p.addParameter('connectivity', 3^numel(gridSize)-1, @isnumeric);
|
223 |
| - p.addParameter('infer_method', @UGM_Infer_LBP, @isfunc); |
| 228 | + p.addParameter('inferMethod', @UGM_Infer_LBP, @isfunc); |
224 | 229 | p.parse(paramvalues{:})
|
225 | 230 | inputs = p.Results;
|
226 | 231 |
|
| 232 | + if ismember('gridIdx', p.UsingDefaults) |
| 233 | + if ~ismember('srcSize', p.UsingDefaults) |
| 234 | + inputs.gridIdx = patchlib.grid(inputs.srcSize, patchSize, patchOverlap); |
| 235 | + |
| 236 | + else |
| 237 | + assert(all(patchOverlap == (patchSize - 1)), 'if not sliding, need source size'); |
| 238 | + inputs.gridIdx = 1:prod(gridSize); |
| 239 | + end |
| 240 | + end |
| 241 | + |
227 | 242 | inputs.patchSize = patchSize;
|
228 | 243 | inputs.patchOverlap = patchOverlap;
|
229 | 244 |
|
|
0 commit comments