imwrite() with PGM option actually write in PBM

조회 수: 2 (최근 30일)
Francesco Clerici
Francesco Clerici 2018년 11월 24일
편집: KALYAN ACHARJYA 2018년 11월 24일
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