- Read using niftiread
- Write using niftiwrite
- Resize them using imresize3
How to resize multiple images nifti?
19 ビュー (過去 30 日間)
古いコメントを表示
mohd akmal masud
2022 年 7 月 24 日
コメント済み: Walter Roberson
2022 年 7 月 27 日
Dear all,
I have 75 folder. each folder have 5 set images. each set images have 240x240x155 size.
how to resize all the images (75 x 5 = 375 set images) from 240x240x155 to 100x100x50?
0 件のコメント
採用された回答
Shivang Srivastava
2022 年 7 月 27 日
Hi,
As per my understanding you want to resize the images present in multiple folders to a new fixed size of 100x100x50.
Since I do not have a sample image of the given dimensions, I will be demonstrating the resizing using a RGB image. You can use the below code to find the images in sub-folders and resize them.
% Find all files present in the parent folder.
currentWorkingDirectory = pwd;
files = dir(currentWorkingDirectory);
% Get a logical vector that tells which is a directory.
dirFlags = [files.isdir];
% Extract only those that are directories.
foldersList = files(dirFlags); % A structure with extra info.
% Get only the folder names into a cell array.
folderNames = {foldersList(3:end).name}; % Start at 3 to skip . and ..
% Make a directory to store the resized images
mkdir resizeImages
for i = 1 : length(folderNames)
folderPath = currentWorkingDirectory + "\" + folderNames{i};
subFolder = dir(folderPath);
dirFlags = [subFolder.isdir];
imageList = subFolder(~dirFlags);
imagesNames = {imageList.name};
for j = 1 : length(imagesNames)
imgPath = folderPath + "\" + imagesNames{j};
% Read Image
I = imread(imgPath);
% Resize Image
Iresize = imresize(I,[100 100]);
% Write Image to the resize folder.
imwrite(Iresize,currentWorkingDirectory+"\"+"resizeImages\"+folderNames{i}+"_"+imagesNames{j});
end
end
For using 3-D volumetric intensity image you can use the following functions:
2 件のコメント
Walter Roberson
2022 年 7 月 27 日
folderNames = {foldersList(3:end).name}; % Start at 3 to skip . and ..
Doing that is incorrect on every operating system that MATLAB has ever been supported on.
- some of the operating systems had no . or .. entries at all
- some of the operating systems have . or .. but do not sort the entries returned to MATLAB's internal directory calls. MATLAB never sorts them itself; MATLAB relies upon the order returned by the operating system
- some of the operating systems only sort for certain kinds of file systems, and it is seldom obvious what kind of file system is being used unless you know the magic to ask
- some of the operating systems do sort, but permit file and directory names that sort before . and ..
- the sorting order for some file systems on some operating systems can silently depend upon the language settings of the person who created the file system
The most common file system MATLAB users are likely to use, is MS Window's NTFS. NTFS never promises to sort entries, but typically sorts -- using an order that permits some entries before . and ..
You should never rely upon . or .. being at a particular location in the directory data. You should always deal with those directly:
mask = ismember({foldersList.name}, {'.', '..'});
folderNames = {foldersList(~mask).name};
Walter Roberson
2022 年 7 月 27 日
folderPath = currentWorkingDirectory + "\" + folderNames{i};
That assumes MS Windows. You should instead be using fullfile:
folderPath = fullfile(currentWorkingDirectory, folderNames{i});
Note: of all of the supported operating systems, MS Windows is the only one that permits \ as a directory separator. The actual internal character used by MS Windows is not \ and is instead / -- so for all currently supported operating systems, / can be used. But using fullfile() is more reliable.
その他の回答 (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!