HOW TO CONVERT PATCH INTO dicom

2 views (last 30 days)
mohd akmal masud
mohd akmal masud on 23 Apr 2022
Edited: mohd akmal masud on 23 Apr 2022
Dear all,
I have coding below. How to convert p to dicom. so that my image segmentation can convert into 16uint and can view as 3D slice or 4D.
all image have attached. (except dicomCTPhantom can download here = https://drive.google.com/drive/folders/1SKuWT7G-qG9Xs_r_fs50BqZqcS4ZzUwq?usp=sharing)
clc
clear all
dataSetDir = fullfile('C:\Users\Akmal\Desktop\latest U-Nett Model 12.01.2022');
imageDir = fullfile(dataSetDir,'bwaftersegmentationpngI13125610N1untukimportdalam3DSlicer');
imds = imageDatastore(imageDir);
for i = 1:142
subplot(13,11,i)
I = readimage(imds,i);
% binary
Is{i} = logical(I);
imshow3D(I)
end
% For 3D images spect
% C:\Users\Akmal\Desktop\latest U-Nett Model 12.01.2022 is folder you located the dicomI13125610N1 images
myFolder = ('C:\Users\Akmal\Desktop\latest U-Nett Model 12.01.2022\dicomI13125610N1');
filePattern = fullfile(myFolder, '*.dcm'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for K = 1 : length(theFiles)
baseFileName = theFiles(K).name;
fullFileName = fullfile(theFiles(K).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()
P(:,:,K) = dicomread(fullFileName);
P(:,:,K) = (P(:,:,K)) .* uint16( Is{K} );
% P(:,:,K) = double(uint8(K).*uint8(Is{K}));
end
% important to know the number after 0
P1 = P(:);
min(P1(P1>0))
size(P)
P = imbinarize(P);
imshow3D(P)
% Get a list of all files in the folder with the desired file name pattern.
myFolder = ('dicomCTPhantom');
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
figure,
imshow3D(RZ)
RZ=double(RZ);
[N M L]=size(RZ);
rats=size(RZ)./size(P);
[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);
RZ = flip(RZ,3);
e=10000;%isovalue, air at 0 (Faceskin800, air1250)
figure
whitebg('black')
colordef none
axis off
pause
fprintf('\nFull Reconstruction. Please wait...\n');
% for e=min(min(min(RZ))):1000:max(max(max(RZ)))
% plot3(0.5,0.5,0.5);
% hold;
q = patch(isosurface(RZ,e));
axis equal
set(q,'FaceColor','w','EdgeColor','none');
alpha(q,0.2)
material shiny
hold
% q = patch(isosurface(RZ,20000));
% axis equal
% set(q,'FaceColor','g','EdgeColor','none');
% alpha(q,1)
% material shiny
camlight('headlight')
% title([num2str(e)]);
view([-22 -4])
% axis([0 M 0 N 0 L]);
% camlight('left')
% pause(0.01)
% grid
% end
p = patch(isosurface(smooth3(smooth3(P))));
axis equal
set(p,'FaceColor','c','EdgeColor','none');
alpha(p,1)
hold
I TRIED USED THIS BELOW COMMAND BUT GOT ERROR
%% this one for imwrite/dicomwrite from binary subplot(imshow3D) to single image binary
% pastikan outt22(:,:,ii) = imopen(outt2,st2); imshow(outt22(:,:,ii)) buat
% dulu kat atas
for k = 1:142
dicomwrite(p(:,:,k),sprintf('%d.dcm',k));
% imwrite(BW1(:,:,k), sprintf(['bwaftersegmentationpngI13125610N1' ...
% '%03d.png'], k)); %allBW is from gradientweight imshow3D
end

Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by