How to rotate image 3D
Show older comments
Dear All,

What I want is like below:

%% Spect
clc
clear all
close all
[spect map]=dicomread('K.dcm');
info = dicominfo('K.dcm');
%gp=info.SliceThickness;
spect=(squeeze(spect));%smooth3
aa=size(spect);aa=aa(3);
imshow3D(spect)
% 1. volume1
BCKG1 =262;
MAX1 =1182;
bckgratio1=MAX1/BCKG1;
seedR1 = 70; seedC1 = 81; seedP1 = 3;
W1 = graydiffweight(spect, seedC1, seedR1, seedP1 , 'GrayDifferenceCutoff', 1000000);
thresh1 =(5*0.00001*(bckgratio1^2))+(0.0008*bckgratio1)-0.0012;
[BW1, D1] = imsegfmm(W1, seedC1, seedR1, seedP1, thresh1);
% figure, imshow3D(BW1)
T1 = regionprops('table', BW1,'Area','Centroid')
figure
imshow3D(BW1);
% 2. volume2
BCKG2 =181 ;
MAX2 =566;
bckgratio2=MAX2/BCKG2;
seedR2 = 74; seedC2 = 73; seedP2 = 3;
W2 = graydiffweight(spect, seedC2, seedR2, seedP2 , 'GrayDifferenceCutoff', 1000000);
thresh2 =(5*0.00001*(bckgratio2^2))+(0.0008*bckgratio2)-0.0012;
[BW2, D2] = imsegfmm(W2, seedC2, seedR2, seedP2, thresh2);
% figure, imshow3D(BW1)
T2 = regionprops('table', BW2,'Area','Centroid')
figure
imshow3D(BW2);
% 3. volume3
BCKG3 =181 ;
MAX3 =557;
bckgratio3=MAX3/BCKG3;
seedR3 = 68; seedC3 = 69; seedP3 = 3;
W3 = graydiffweight(spect, seedC3, seedR3, seedP3 , 'GrayDifferenceCutoff', 1000000);
thresh3 =(5*0.00001*(bckgratio3^2))+(0.0008*bckgratio3)-0.0012;
[BW3, D3] = imsegfmm(W3, seedC3, seedR3, seedP3, thresh3);
% figure, imshow3D(BW1)
T3 = regionprops('table', BW3,'Area','Centroid')
figure
imshow3D(BW3);
% 4. volume4
BCKG4 =181 ;
MAX4 =536;
bckgratio4=MAX4/BCKG4;
seedR4 = 71; seedC4 = 59; seedP4 = 3;
W4 = graydiffweight(spect, seedC4, seedR4, seedP4 , 'GrayDifferenceCutoff', 1000000);
thresh4 =(5*0.00001*(bckgratio4^2))+(0.0008*bckgratio4)-0.0012;
[BW4, D4] = imsegfmm(W4, seedC4, seedR4, seedP4, thresh4);
% figure, imshow3D(BW1)
T4 = regionprops('table', BW4,'Area','Centroid')
figure
imshow3D(BW4);
% 5. volume5
BCKG5 =181 ;
MAX5 =504;
bckgratio5=MAX5/BCKG5;
seedR5 = 81; seedC5 = 54; seedP5 = 3;
W5 = graydiffweight(spect, seedC5, seedR5, seedP5 , 'GrayDifferenceCutoff', 1000000);
thresh5 =(5*0.00001*(bckgratio5^2))+(0.0008*bckgratio5)-0.0012;
[BW5, D5] = imsegfmm(W5, seedC5, seedR5, seedP5, thresh5);
% figure, imshow3D(BW1)
T5 = regionprops('table', BW5,'Area','Centroid')
figure
imshow3D(BW5);
% 6. volume6
BCKG6 =294 ;
MAX6 =520;
bckgratio6=MAX6/BCKG6;
seedR6 = 77; seedC6 = 44; seedP6 = 3;
W6 = graydiffweight(spect, seedC6, seedR6, seedP6 , 'GrayDifferenceCutoff', 1000000);
thresh6 =(5*0.00001*(bckgratio6^2))+(0.0008*bckgratio6)-0.0012;
[BW6, D6] = imsegfmm(W6, seedC6, seedR6, seedP6, thresh6);
% figure, imshow3D(BW1)
T6 = regionprops('table', BW6,'Area','Centroid')
figure
imshow3D(BW6);
% 7. volume7 (Salivary Gland)
BCKG7 =181 ;
MAX7 =1380;
bckgratio7=MAX7/BCKG7;
seedR7 = 50; seedC7 = 67; seedP7 = 65;
W7 = graydiffweight(spect, seedC7, seedR7, seedP7 , 'GrayDifferenceCutoff', 1000000);
thresh7 =(5*0.00001*(bckgratio7^2))+(0.0008*bckgratio7)-0.0012;
[BW7, D7] = imsegfmm(W7, seedC7, seedR7, seedP7, thresh7);
% figure, imshow3D(BW1)
T7 = regionprops('table', BW7,'Area','Centroid')
figure
imshow3D(BW7);
% 8. volume8 (Salivary Gland)
BCKG8 =181 ;
MAX8 =1240;
bckgratio8=MAX8/BCKG8;
seedR8 = 47; seedC8 = 73; seedP8 = 64;
W8 = graydiffweight(spect, seedC8, seedR8, seedP8 , 'GrayDifferenceCutoff', 1000000);
thresh8 =(5*0.00001*(bckgratio8^2))+(0.0008*bckgratio8)-0.0012;
[BW8, D8] = imsegfmm(W8, seedC8, seedR8, seedP8, thresh8);
% figure, imshow3D(BW1)
T8 = regionprops('table', BW8,'Area','Centroid')
figure
imshow3D(BW8);
allBW = BW1 | BW2 | BW3 | BW4 | BW5 | BW6 | BW7 | BW8;
imshow3D(allBW);
totalcountseachblob = sum(spect(allBW==1))
% Get a list of all files in the folder with the desired file name pattern.
myFolder = ('C:\Users\User\Desktop\New folder\K');
filePattern = fullfile(myFolder, '*.dcm'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for L = 1 : length(theFiles)
baseFileName = theFiles(L).name;
fullFileName = fullfile(theFiles(L).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
RZ(:,:,L) = dicomread(fullFileName);
end
RZ=double(RZ);
[N M L]=size(RZ);
rats=size(RZ)./size(spect);
[x,y,z]=meshgrid(rats(1):rats(1):M,rats(2):rats(2):N,rats(3):rats(3):L);
RZ=interp3(RZ,x,y,z);
e=10000;%isovalue, air at 0 (Faceskin800, air1250)
figure
whitebg('black')
colordef none
axis off
pause
fprintf('\nFull Reconstruction. Please wait...\n');
q = patch(isosurface(RZ,e));
axis equal
set(q,'FaceColor','w','EdgeColor','none');
alpha(q,0.2)
material shiny
hold
camlight('headlight')
% title([num2str(e)]);
view([-22 -4])
p = patch(isosurface(allBW));
axis equal
set(p,'FaceColor','c','EdgeColor','none');
alpha(p,1)
hold
4 Comments
Cris LaPierre
on 25 Dec 2024
If you zip your dcm file, you can attach it to your post using the paperclip icon. We could then provide more specific instructions.
In the meantime, you may consider using medicalvolume to load your dicom instead of dicomread. It will take into consideration the orientation of the acquired data.
The MathWorks released the Medical Imaging Toolbox last year and then this year launched a Medical Image Processing course on Coursera. You may find that helpful, and you can enroll for free.
mohd akmal masud
on 25 Dec 2024
mohd akmal masud
on 26 Dec 2024
Adam Danz
on 26 Dec 2024
I noticed your use of colordef and whitebg.
These functions are removed in an upcoming release. Instead, set your figure color to black and your axes color to "none". Alternatively, set the figure's theme to "dark" if you're using the beta desktop of a future release.
Accepted Answer
More Answers (0)
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!



