Azzera filtri
Azzera filtri

mean surface distance and residual mean square distance of 2 borders

13 visualizzazioni (ultimi 30 giorni)
hi every body. I have 2 borders of 2 surfaces called S1 and S2. I need to compute the surface distance and after that the mean surface distance and residual mean square distance from that.
A complete description of the concept and the code in python is presented in https://mlnotebook.github.io/post/surface-distance-function/
Is there any matlab code for that?
Thanks in advance

Risposta accettata

Image Analyst
Image Analyst il 26 Giu 2020
You can simply use sqrt() and min():
x1 = S1(:, 1);
y1 = S1(:, 2);
x2 = S2(:, 1);
y2 = S2(:, 2);
for k = 1 : length(S1)
% Get the distance from the kth point of S1 to all points in S2.
distances = sqrt((x1(k) - x2) .^ 2 + (y1(k) - y2) .^ 2);
% Find the min of those distances to find how how close point k came to curve 2
minDistance(k) = min(distances);
end
If you have 3-D (x,y,z) coordinates, the extension to 3-D should be obvious.
  6 Commenti
Image Analyst
Image Analyst il 30 Giu 2020
You didn't get the boundaries correctly. The boundaries are not an edge image, you need to call bwboundaries().
Image Analyst
Image Analyst il 1 Lug 2020
talayeh, try this:
clc; % Clear the command window.
fprintf('Beginning to run %s.m.\n', mfilename);
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Read in and display the images.
image1=imread('ECHO-mask.jpg');
image1 = imbinarize(image1);
% Fill holes
image1 = imfill(image1, 'holes');
subplot(1, 2, 1);
imshow(image1, []);
title('ECHO-mask.jpg');
image2=rgb2gray(imread('CTBWslice.jpg'));
image2 = imbinarize(image2);
% Fill holes
image2 = imfill(image2, 'holes');
subplot(1, 2, 2);
imshow(image2, []);
title('CTBWslice.jpg');
% Get the boundaries
boundaries1 = bwboundaries(image1);
boundaries2 = bwboundaries(image2);
for k1 = 1 : length(boundaries1)
b1 = boundaries1{k1};
S1 = fliplr(b1); % Flip so it's (x,y), not (row, column).
for k2 = 1 : length(boundaries2)
b2 = boundaries2{k2};
S2 = fliplr(b2); % Flip so it's (x,y), not (row, column).
%%%% S1 and S2 are two contours
x1 = S1(:, 1);
y1 = S1(:, 2);
x2 = S2(:, 1);
y2 = S2(:, 2);
for k = 1 : length(S1)
% Get the distance from the kth point of S1 to all points in S2.
distances = sqrt((x1(k) - x2) .^ 2 + (y1(k) - y2) .^ 2);
% Find the min of those distances to find how how close point k came to curve 2
minDistance1(k) = min(distances);
end
for k = 1 : length(S2)
% Get the distance from the kth point of S2 to all points in S1.
distances = sqrt((x2(k) - x1) .^ 2 + (y2(k) - y1) .^ 2);
% Find the min of those distances to find how how close point k came to curve 1
minDistance2(k) = min(distances);
end
% Compute the metrics we're interested in.
numPairs = numel(x1) + numel(x2);
MSD = (sum(minDistance1) + sum(minDistance2)) / numPairs;
RMS = sqrt((sum(minDistance1.^2) + sum(minDistance2.^2)) / numPairs);
fprintf('Comparing image1 boundary #%d with image2 boundary #%d,\n we get MSD = %f, and RMS = %f.\n',...
k1, k2, MSD, RMS);
end
end
fprintf('Done running %s.m.\n', mfilename);
In the command window, you'll see:
Comparing image1 boundary #1 with image2 boundary #1,
we get MSD = 5.545358, and RMS = 7.403608.
Comparing image1 boundary #1 with image2 boundary #2,
we get MSD = 60.859496, and RMS = 75.365100.
Comparing image1 boundary #2 with image2 boundary #1,
we get MSD = 57.429919, and RMS = 74.059752.
Comparing image1 boundary #2 with image2 boundary #2,
we get MSD = 3.204780, and RMS = 8.873175.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by