how to automatically Crop images in a folder and save them in an other folder?

1 Ansicht (letzte 30 Tage)
I have a sequence of dicom images named S000009.dcm S0000010.dcm etc. I want to crop them with known values and save them in another folder which I create with mkdir. So far, I have come up with this. Any idea why is not working?
imageDir = 'C:\Echo Images\Stelios\FDB.dcm';
im_Set = imageSet(imageDir);
destinationFolder = 'C:\Echo Images\Stelios\FDB.dcm\imagefolder2';
if ~exist(destinationFolder, 'dir')
mkdir(destinationFolder);
end
for k = 1 : im_Set.Count
theImage = dicomread(im_Set,'#%d.dcm')
croppedImage = imcrop(theImage,[200.5 59.75 591 480]);
baseFileName = sprintf('Image #%d.dcm', k);
fullFileName = fullfile(imageDir, baseFileName);
dicomwrite(croppedImage,destinationFolder);
movefile(croppedImage,destinationFolder,'f')
end
  3 Kommentare
Image Analyst
Image Analyst am 30 Apr. 2018
Tell us what "doesn't work" means to you. Is it not creating the folder? Not cropping? Not moving? I have no idea.
Guillaume
Guillaume am 30 Apr. 2018
Never used dicom images, but is that line
theImage = dicomread(im_Set,'#%d.dcm')
even valid. The documentation does not show a syntax where only two inputs is valid.
Why are you creating fullFileName and never use it? Why are you using imageDir instead of destinationFolder to construct fullFileName? Why are passing an image matrix to movefile instead of a file name?
Honestly, there isn't much that make sense in the code given. No wonder it doesn't work.

Melden Sie sich an, um zu kommentieren.

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