how to automatically Crop images in a folder and save them in an other folder?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Image Analyst
le 30 Avr 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
le 30 Avr 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.
Réponses (0)
Voir également
Catégories
En savoir plus sur Convert Image Type dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!