imwrite() with PGM option actually write in PBM

2 Ansichten (letzte 30 Tage)
Francesco Clerici
Francesco Clerici am 24 Nov. 2018
Bearbeitet: KALYAN ACHARJYA am 24 Nov. 2018
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

Antworten (1)

KALYAN ACHARJYA
KALYAN ACHARJYA am 24 Nov. 2018
Bearbeitet: KALYAN ACHARJYA am 24 Nov. 2018
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

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by