Calculating Surface Curvature from Image Data
18 views (last 30 days)
Show older comments
Hello,
I'm trying to calculate the curvature of each surface point from a morphology picture. However, when using surfature(), I do not get the results I want. A lot of points have a gaussian curvature of 0, which is not plausible for the example I use.
I tried a lot of different methods for calculating and ploting, but never got a good result...
I wrote the following:
% reading in picture
data = imread("Morphology.PNG");
% if not yet, convert to gray image
if size(data, 3) == 3
data = rgb2gray(data);
end
% smoothing image
data = imgaussfilt(data, 4);
% converting to double
data = double(data);
z = data;
% generating 2D arrays for X and Y with size of data-dimensions
[Rows, Cols] = size(data);
[x, y] = meshgrid(1:Cols, 1:Rows);
% calculating gaussian and normal curvature
[K, H] = surfature(x, y, data);
% display surface
figure;
surf(x, y, z, "EdgeColor","none");
title('Surface Morphology');
colorbar;
% ploting the results
figure;
surf(x, y, z, K, "EdgeColor","none");
title('3D Surface Gaussian Curvature Map');
colorbar;
disp(K);
0 Comments
Accepted Answer
Mathieu NOE
on 5 Jun 2024
hello
I think this is because your K array contains some high amplitude spikes that avoid you see the smaller amplitude signals
so I decide to scale the imagesc (and not surf) plot using the mean of abs(K) as a starting point (then you can also add another scaling factor from there) and then the K plot shows up correctly
as I don't have the Image Processing Tbx , I replaced imgaussfilt with a Fex submission (smooth2a) but that is secondary in the problem - you can of course use imgaussfilt on your side as you did in the first place
this is my K plot so far :
code updated :
% reading in picture
data = imread("Morphology.png");
% if not yet, convert to gray image
if size(data, 3) == 3
data = rgb2gray(data);
end
% smoothing image
% data = imgaussfilt(data, 4); % you
% converting to double
data = double(data);
% smoothing image
data = smooth2a(data,10,10); % me
% generating 2D arrays for X and Y with size of data-dimensions
[Rows, Cols] = size(data);
[x, y] = meshgrid(1:Cols, 1:Rows);
% calculating gaussian and normal curvature
[K, H] = surfature(x, y, data);
% display surface
figure;
imagesc(data);
title('Surface Morphology');
colorbar;
% ploting the results
figure;
imagesc(K);
K_mean = mean(abs(K),'all');
amplitude = 3*K_mean; % eventually apply a scaling factor to K_mean
caxis([-amplitude amplitude]);
title('3D Surface Gaussian Curvature Map');
colorbar;
5 Comments
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!