# Imgradient3 function: can we used this function for finding chnage in gradient of surface points.

2 visualizzazioni (ultimi 30 giorni)
Saurav il 9 Apr 2024
Commentato: Arun il 23 Apr 2024
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 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Mathieu NOE il 15 Apr 2024
Modificato: Mathieu NOE il 15 Apr 2024

Accedi per commentare.

### Risposte (1)

Arun il 17 Apr 2024
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.
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;
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
Step-3 : Use the “imgradient3” function to get the gradient magnitude for the image.
%Step-3
Step-4 : Apply the “gradient” function to calculate the change.
%Step-4
This will help to calculate the change in gradient of the points for a 3-D image.
I hope this helps.
##### 6 CommentiMostra 4 commenti meno recentiNascondi 4 commenti meno recenti
Saurav il 23 Apr 2024
Here is the code
I have attached the tiff stack folder as well as stl image file.
TR=stlread('aggregate_1.stl'); %% This is stl file image created from 3d stacked image
trimesh(TR); %% i have attached the stl file as well
% fid = fopen('VA1.vol');
% voxels = fread(fid); %read as 16 bit unsigned. I'm assuming they're unsigned
% volumeViewer(voxels);
%number images with 1.tiff-N.tiff
files = dir('/MATLAB Drive/tiff3/*.tif');
%disp(files);
for ii = 2 : size(files, 1)
tiff_stack = cat(3 , tiff_stack, temp_tiff);
end
% %volumeViewer(tiff_stack);
% isosurf = isosurface(tiff_stack, 100);
% faces = isosurf.faces;
% vertices = isosurf.vertices;
Arun il 23 Apr 2024
I executed the code shared by you, sharing my finding for the problems mentioned in previous comment:
1. Problem-1: tiff_stack contains non-zero values.
2. Problem-2: Gx, Gy and Gz have non-zero values.
3. 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.

Accedi per commentare.

### Categorie

Scopri di più su 3-D Volumetric Image Processing in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by