how to convert 5 dcm images to 5 png images

조회 수: 1 (최근 30일)
mohd akmal masud
mohd akmal masud 2021년 1월 27일
댓글: mohd akmal masud 2021년 2월 5일
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?

채택된 답변

yanqi liu
yanqi liu 2021년 2월 1일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by