Skip to content

Commit

Permalink
possible normalization for HD
Browse files Browse the repository at this point in the history
updated in the inputs for normalization and display
also added the inner loop for normalization - but this one is likely
wrong
  • Loading branch information
CPernet committed Jul 14, 2016
1 parent e326161 commit 4aaee4a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
44 changes: 38 additions & 6 deletions validation/crc_meanHausdorffDist.m
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
function [mD,D12,D21] = crc_meanHausdorffDist(xyz1,xyz2)
function [mD,D12,D21] = crc_meanHausdorffDist(varargin)
% Calculate the mean Hausdorff distance between 2 surfaces, based on the
% coordinates of the voxels of these surfaces.
% This implementation only works with 3D volumes but is much faster than
% standard implementations (with for-loops).
%
% FORMAT
% [mD,D12,D21] = crc_meanHausdorffDist(xyz1,xyz2)
% [mD,D12,D21] = crc_meanHausdorffDist(xyz1,xyz2,'normalize','true','display','false')
%
% INPUT
% xyz1/2 coordinates of voxels on borders in both images
% normalize is 'true' or 'false' (default)
% --> distances are normalized by the max
% display is 'true' of 'false' to show results with histogram
%
% OUTPUT
% mD mean distances between surface in images 1-2 and 2-1
Expand All @@ -18,10 +21,35 @@

% Written by Christophe Phillips
% University of Liege, Belgium
% updated inputs and normalization C. Pernet , University of Edinburgh

% Switch to true to get some stats and plots generated.
fl_disp = false;
%% Set defaults

normalize = 0; % do not normalize
display = false; % Switch to true to get some stats and plots generated.

%% Check inputs
xyz1 = varargin{1};
xyz2 = varargin{2};

not_recognized = 0;
if nargin > 2
for ii=3:2:nargin
if strcmpi(varargin(ii),'normalize')
normalize = varargin{ii+1};
elseif strcmpi(varargin(ii),'normalize')
display = varargin{ii+1};
else
not_recognized = 1;
end
end
end

if not_recognized == 1
disp('optional input not recognized, using defaults');
end

%% Compute
% Make sure that the coordinates are in N x 3 format
SZ1 = size(xyz1);
if SZ1(1)<SZ1(2)
Expand All @@ -42,12 +70,16 @@
(xyz2(:,3)-xyz1(ii,3)).^2 ); % voxels in 2nd image
D12(ii) = min(Dtmp); % smallest distance from i_th voxel in 1st image
D21 = min(D21,Dtmp); % smallest distance for all voxels in 2nd image
if normalize

This comment has been minimized.

Copy link
@ChristophePhillips

ChristophePhillips Nov 21, 2016

Member

@CPernet
It seems to me that this scaling should NOT occur within the loop, otherwise the D12/D21 values could end up being scaled mulitple times... Are you sure of this bit of the code?
Cf issue #6

This comment has been minimized.

Copy link
@CPernet

CPernet Nov 23, 2016

Author Collaborator

nope not sure - I left it FYI but did not used it on the validation as we discussed it and though that would not work -- remove it

D12 = D12 ./ max(D12);
D21 = D21 ./ max(D21);
end
end

mD = [mean(D12) mean(D21)];

% provide some stats and evaluation
if fl_disp
if display
mM = [ min(D12) max(D12) median(D12) ; min(D21) max(D21) median(D12) ]; %#ok<*UNRCH>
fprintf('\n')
fprintf('D12 mean/min/max/median: %1.2f / %1.2f / %1.2f / %1.2f',mD(1),mM(1,:))
Expand All @@ -64,7 +96,7 @@
[H21,bi] = hist(D21,Nbins);
H12 = hist(D12,bi);
end
figure, bar(bi,[H12' H21'])
figure, bar(bi,[H12' H21'])
legend('D12','D21')
end
end
2 changes: 1 addition & 1 deletion validation/image_overlap.m
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
Bxyz1_mm = v2r(1:3,1:3)* [iBx1' ; iBy1' ; iBz1'];
Bxyz2_mm = v2r(1:3,1:3)* [iBx2' ; iBy2' ; iBz2'];

[mD,D12,D21] = crc_meanHausdorffDist(Bxyz1_mm,Bxyz2_mm); %#ok<*ASGLU>
[mD,D12,D21] = crc_meanHausdorffDist(Bxyz1_mm,Bxyz2_mm,'normalize','true');
mHd = mean(mD);

%% Overlap measures to ground truth
Expand Down

0 comments on commit 4aaee4a

Please sign in to comment.