Skip to content

Commit 70868fc

Browse files
committed
update patchmrf edge distance and inferMethod
1 parent c9c2c63 commit 70868fc

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

src/+patchlib/correspdst.m

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
function dst = correspdst(pstr1, pstr2, ~, ~, dvFact, usemex)
2+
% TODO: take out the dvFact.
3+
% TODO: the limit should be passed in (?)
4+
%
5+
% TODO: redo function to behave like
6+
% dst = (pstr1, pstr2, params)
7+
% with params being:
8+
% dvFact (??) <-- maybe not necessary
9+
% usemex
10+
% maxDist (??) <-- maybe not necessary
211

312
if nargin <= 4 || isempty(dvFact)
413
dvFact = 100;
@@ -20,12 +29,13 @@
2029
% that checks for (exist('pdist2mex', 'file') == 3) would be very costly, since that's a file
2130
% system check at every call.
2231
if usemex
23-
dst = pdist2mex(X',Y','euc',[],[],[]);
32+
dst = pdist2mex(X', Y', 'euc', [], [], []);
33+
2434
else
25-
dst = pdist2(pstr1.disp ./ dvFact, pstr2.disp ./dvFact);
35+
dst = pdist2(X, Y);
2636
end
2737

28-
dst = min(dst, 1);
38+
% dst = min(dst, 1);
2939

3040
% error('this might be wrong. need to subtract patchOverlap from patches2?');
3141
end

src/+patchlib/patchmrf.m

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,25 @@
5858
% extract max nodes. TODO: look into UGM decode methods.
5959
[~, maxNodes] = max(nodeBel, [], 2);
6060

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
6367
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+
6570
pIdxSel = []; rIdxSel = [];
6671
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);
6974
end
7075

7176
% prepare outputs
7277
belstruct = structrich(nodeBel, edgeBel, logZ, maxNodes);
7378
potstruct = structrich(nodePot, edgePot, edgeStruct);
74-
vargout = {belstruct, potstruct, qSel, pIdxSel, rIdxSel};
79+
vargout = {belstruct, potstruct, qSelIdx, pIdxSel, rIdxSel};
7580
varargout = vargout(1:nargout);
7681
end
7782

@@ -217,13 +222,23 @@
217222
p.addParameter('pIdx', [], @isnumeric);
218223
p.addParameter('rIdx', [], @isnumeric);
219224
p.addParameter('refgridsize', [], @(x) isnumeric(x) || iscell(x));
220-
p.addParameter('gridIdx', 1:prod(gridSize), @isnumeric);
225+
p.addParameter('gridIdx', [], @isnumeric);
221226
p.addParameter('srcSize', [], @isnumeric);
222227
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);
224229
p.parse(paramvalues{:})
225230
inputs = p.Results;
226231

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+
227242
inputs.patchSize = patchSize;
228243
inputs.patchOverlap = patchOverlap;
229244

0 commit comments

Comments
 (0)