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!