dicom pixel value matrix into CVS file

1 Ansicht (letzte 30 Tage)
Deepa S
Deepa S am 27 Aug. 2020
Kommentiert: Deepa S am 7 Sep. 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 Kommentare
Rik
Rik am 3 Sep. 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 am 7 Sep. 2020
i got it. thankyou

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 3 Sep. 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 Kommentare
Rik
Rik am 7 Sep. 2020
If it works, why not mark the answer as accepted? And please don't post comments in flags.
Deepa S
Deepa S am 7 Sep. 2020
okay.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

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