Imgradient3 function: can we used this function for finding chnage in gradient of surface points.
5 ビュー (過去 30 日間)
古いコメントを表示
I generated coordinates by converting 3d image to stl. Now I want to give the x coordinates, y coordinates and z coordinates of all the ponts as input in imgradient3 function. Means instead of Gx, Gy and Gz can we put Intx, Inty and Intz in that function. intx isx coordinates of all the genrated points using surface meshing. I am interested in finding the change in gradient of all the points with respect to their neighbours.
1 件のコメント
回答 (1 件)
Arun
2024 年 4 月 17 日
Hi Saurav,
I understand that you wish to calculate change in gradient of all the points with respect to their neighbours for a 3-D image.
Below are the steps along with code snippets that could assist in finding the gradient of all the points for a 3-D image and then finally change in gradient of all the points with respect to their neighbours:
Step-1 : Acquire/Load the image. The below code creates a 3-D image to be used, one can use an existing image as well.
% Step-1:Add 3D image
dims = [100, 100, 100];
image3D = zeros(dims); % Initialize with zeros
[x, y, z] = ndgrid(1:dims(1), 1:dims(2), 1:dims(3));
center = dims/2;
radius = 30;
sphere = sqrt((x-center(1)).^2 + (y-center(2)).^2 + (z-center(3)).^2) <= radius;
image3D(sphere) = 1; % Assign a value to voxels inside the sphere
cubeStart = [30, 30, 30];
cubeEnd = [60, 60, 60];
image3D(cubeStart(1):cubeEnd(1), cubeStart(2):cubeEnd(2), cubeStart(3):cubeEnd(3)) = 2; % Assign a different value to the cube
% Display the image
figure;
p1 = patch(isosurface(image3D, 0.5));
set(p1, 'FaceColor', 'red', 'EdgeColor', 'none');
daspect([1,1,1]);
view(3); axis tight;
camlight; lighting gouraud;
Step-2 : Utilize the “imgradientxyz” function to get the directional gradients “Gx”, ”Gy”, and “Gz”.
%Step-2
[Gx, Gy, Gz] = imgradientxyz(image3D);
Step-3 : Use the “imgradient3” function to get the gradient magnitude for the image.
%Step-3
[Gmag,Gazimuth,Gelevation] = imgradient3(Gx,Gy,Gz);
Step-4 : Apply the “gradient” function to calculate the change.
%Step-4
[dx, dy, dz] = gradient(Gmag);
This will help to calculate the change in gradient of the points for a 3-D image.
Please refer to the shared MATLAB documentation links for more information:
2. “imgradient3” function -: https://www.mathworks.com/help/images/ref/imgradient3.html
3. “gradient” function -: https://www.mathworks.com/help/matlab/ref/gradient.html
I hope this helps.
6 件のコメント
Arun
2024 年 4 月 23 日
I executed the code shared by you, sharing my finding for the problems mentioned in previous comment:
- Problem-1: tiff_stack contains non-zero values.
- Problem-2: Gx, Gy and Gz have non-zero values.
- Problem-3: No issue while execution, in MATLAB R2024a.
To verify please use the below lines of code at the end of the shared code:
noOfNonZeroValuesInTiff_stack = size(find(tiff_stack~=0),1)
noOfNonZeroValuesInGx = size(find(Gx~=0),1)
noOfNonZeroValuesInDx = size(find(dx~=0),1)
Here is the snapshot of the output after the execution:
Hope this helps, please do let me know if you face any issue.
参考
カテゴリ
Help Center および File Exchange で 3-D Volumetric Image Processing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!