dicom pixel value matrix into CVS file

1 visualización (últimos 30 días)
Deepa S
Deepa S el 27 de Ag. de 2020
Comentada: Deepa S el 7 de Sept. de 2020
I have 50 dicom files in one folder. i need to transfer pixel matrix of each image file into one common csv file and also the next image matrix must start from the next row in the same csv file. here is my code.
myFolder = ' ';
filePattern = fullfile(myFolder, '*.dcm');
image = dir(filePattern);
for k = 1:length(image)
baseFileName = image(k).name;
fullFileName = fullfile(myFolder, baseFileName);
I= dicomread(fullFileName);
rowImage = reshape(I, 1, []);
if k == 1
csvwrite('file.csv', rowImage, 'delimeter',',');
else
csvwrite('file.csv', rowImage, 'delimiter',',','-append');
end
end
my code is not doing the thing i want . Anyone who can help with this code would be appreciated.
  13 comentarios
Rik
Rik el 3 de Sept. de 2020
You don't need to spread the things you want to say over separate comments.
If you know how to read a file and how to write a file, what steps are unclear to you?
Deepa S
Deepa S el 7 de Sept. de 2020
i got it. thankyou

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 3 de Sept. de 2020
Writing each dcm file to a separate column:
myFolder = '403498/New';
outfile = fullfile(myFolder, 'file.csv');
filePattern = fullfile(myFolder, '*.dcm');
dcmimage = dir(filePattern);
numfiles = length(dcmimage);
images = nan(1, numfiles);
for k = 1:numfiles
baseFileName = dcmimage(k).name;
fullFileName = fullfile(myFolder, baseFileName);
I = reshape(dicomread(fullFileName), [], 1);
numI = numel(I);
cursize = size(images,1);
if cursize < numI
images(end+1:numI,:) = nan;
elseif numI < cursize
I(end+1:cursize) = nan;
end
images(:,k) = I;
end
dlmwrite(outfile, images)
Because each file might be a different length, this pads with nan out to the longest file. It is possible to write out empty cells instead, but the file writing portion would be more work.
Note that it would be common for dcm files to have more than 1048576 elements, which is the maximum row limit for xlsx files. If you were planning and processing this csv file through excel or any tool uses excel to read csv files (such as xlsread()) then you are probably going to have problems.
I think you should be reconsidering writing the pixel values as text all into a common file.
  3 comentarios
Rik
Rik el 7 de Sept. de 2020
If it works, why not mark the answer as accepted? And please don't post comments in flags.
Deepa S
Deepa S el 7 de Sept. de 2020
okay.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by