![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1709581/image.png)
Calculating Surface Curvature from Image Data
10 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Mathieu NOE
2024-6-5
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 :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1709581/image.png)
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;
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!