-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated in the inputs for normalization and display also added the inner loop for normalization - but this one is likely wrong
- Loading branch information
Showing
2 changed files
with
39 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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) | ||
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
CPernet
Author
Collaborator
|
||
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,:)) | ||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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