how to automatically Crop images in a folder and save them in an other folder?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Image Analyst
2018-4-30
Tell us what "doesn't work" means to you. Is it not creating the folder? Not cropping? Not moving? I have no idea.
Guillaume
2018-4-30
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.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!