imwrite() with PGM option actually write in PBM

2 次查看(过去 30 天)
Hi all, I am trying to convert DICOM images in PGM images for a software I am using. dicomread() reads them correctly, but when it comes to use imwrite(), it provides PBM images (I check it using Mac infos, and using the fact that on the program I am writing gives me an error when I use those images, a wrong-extension-error). Note that if I try other formats like png it works.
The code is the following:
clear all; close all; clc;
MM = 1686; % maximum value for normalization
mm = -2048; % minimum value
for ii=1:331
str = strcat('/my/path/IM-0001-',num,'-0001.dcm'); % DICOM image name
info = dicominfo(str,'UseDictionaryVR',true); % DICOM info
Y = double(dicomread(info)); % read
Y = (Y-mm)./(MM-mm); % normalize
titleSlice = strcat('/my/path/slice',num2str(ii),'.pgm'); % output name
imwrite(Y,titleSlice,'pgm'); % imwrite() which provides PBM and not PGM
end

回答(1 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2018-11-24
编辑:KALYAN ACHARJYA 2018-11-24
Follow this way, its works to write the dicom in pgm format
path_directory='dcm_sample_images'; % 'Folder name'
original_files=dir([path_directory '/*.dcm']);
for j=1:3
filename=[path_directory '/' original_files(j).name];
I1=double(dicomread(filename));
%do your findings, say I2 is results
path_folder='D:\JNU jaipur\PhD\Matlab Work\dicom_write_test';
baseFileName=sprintf('%d.pgm',j);
fullFileName=fullfile(path_folder,baseFileName); % No need to worry about slashes now!
imwrite(I2,fullFileName);
end
222.png
111.png

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by