how to convert 5 dcm images to 5 png images

2 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

yanqi liu
yanqi liu il 1 Feb 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

Più risposte (0)

Categorie

Scopri di più su Images in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by