how to convert 5 dcm images to 5 png images

2 Ansichten (letzte 30 Tage)
mohd akmal masud
mohd akmal masud am 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?

Akzeptierte Antwort

yanqi liu
yanqi liu am 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

Weitere Antworten (0)

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by