how to automatically Crop images in a folder and save them in an other folder?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Image Analyst
el 30 de Abr. de 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
el 30 de Abr. de 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.
Respuestas (0)
Ver también
Categorías
Más información sobre Convert Image Type en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!