How do I make 3D sphere for convolution?
Show older comments
Hi all,
I want to make a 3D sphere where the x, y and z coordinates are being solved in a 3D array, so I can convolute this with a kernel I have. But, I don't seem to both save the coordinates and get the shape right at the same time. I have the following code:
figure;
half=50;
for k=1:100
for j=1:100
for i=1:100
mesh_sphere(i,j,k)=((i-half).^2)+((j-half).^2)+((k-half).^2);
end
end
surf(mesh_sphere(:,:,k));
hold on
end
hold off
After this, I also want to use other shapes that I can test my kernel on, such as a hollow sphere and an ellipsoid. How can I make those and also same them in a 3D array? Thank you in advance!
Accepted Answer
More Answers (1)
Image Analyst
on 12 Jan 2022
Edited: Image Analyst
on 13 Jan 2022
SE = strel('sphere',r) % creates a 3-D spherical structuring element whose radius is r pixels.
out = convn(inputImage, SE.Neighborhood);
3 Comments
Matt J
on 12 Jan 2022
Possibly you meant,
out = convn(inputImage, SE.Neighborhood);
Rik
on 12 Jan 2022
I don't remember this object notation. Admittedly, I haven't used this function in years, but I will look up this function in the release notes to see whether I forgot, or if they changed it.
Image Analyst
on 12 Jan 2022
Thanks Matt for the correction.
Categories
Find more on Surface and Mesh Plots 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!
