how to convert 5 dcm images to 5 png images

2 vues (au cours des 30 derniers jours)
mohd akmal masud
mohd akmal masud le 27 Jan 2021
Hi all, i have 5 dicom images. i want to convert it to png images.
clc
clear all
% Get a list of all files in the folder with the desired file name pattern.
myFolder = 'C:\Users\Akmal\Documents\MATLAB\Add-Ons\Functions\Region Growing\ct koh';
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, map] = dicomread(fullFileName);
RZ11(:,:,L) = im2uint16(RZ(:,:,L) );
dcmImagei(:,:,L) = uint8(255 * mat2gray( RZ11(:,:,L) ));
imwrite(dcmImagei(:,:,L),'qqqmyGray.png');
BUT MY PROBLEM IS JUST ONE IMAGE PRODUCE. HOW ABOUT TO PRODUCE ANOTHER 4?

Réponse acceptée

yanqi liu
yanqi liu le 1 Fév 2021
clc; clear all; close all;
% Get a list of all files in the folder with the desired file name pattern.
myFolder = 'C:\Users\Akmal\Documents\MATLAB\Add-Ons\Functions\Region Growing\ct koh';
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);
RZ11(:,:,L) = im2uint16(RZ(:,:,L) );
dcmImagei(:,:,L) = uint8(255 * mat2gray( RZ11(:,:,L) ));
imwrite(dcmImagei(:,:,L), sprintf('qqqmyGray%d.png', L));
end
  1 commentaire
mohd akmal masud
mohd akmal masud le 5 Fév 2021
Great!! Its work. Thank you so much

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by