How to modify the images, were read by "dir" function?
3 ビュー (過去 30 日間)
古いコメントを表示
Hello, So nice guys.
Can you help me?
I did print out many images like this below.
--------------------------------------
path='C:\'
list=dir(path)
name={list.name}
imagelist=name(3:end)
montage(imagelist)
-------------------------------------
I want to modify (example: imrotate, im2gray etc..) the images before I print out the images (montage);
Also, I want to save these images using function imwrite.
But, I couldn't,,
So, What can I do for this?
Thank you
1 件のコメント
Stephen23
2024 年 9 月 20 日
As an aside, note that
imagelist=name(3:end)
is a buggy attempt to remove the dot directory names:
https://www.mathworks.com/matlabcentral/answers/1699230-folder-listing-with-dir-on-mac#answer_945260
As Walter Roberson wrote: "That code is wrong on every operating system that MATLAB has ever run on".
The recommended approach is to specify a non-empty DIR search name, or use e.g. ISMEMBER, SETDIFF, or similar:
回答 (2 件)
dpb
2024 年 9 月 16 日
montage returns only an montage object; not the individual images. Review the information at <Image Sequences and Batch Processing> and select from the various options outlined the best that matches your needed workflow to process each image.
0 件のコメント
Angelo Yeo
2024 年 9 月 20 日
編集済み: Angelo Yeo
2024 年 9 月 20 日
Neither imrotate nor im2gray support sequence image processing so I believe it would be good to use for loops in this case.
imds = imageDatastore(fullfile(matlabroot,"toolbox","images","imdata","AT3*.tif"));
figure; montage(imds); title('original image set')
N = length(imds.Files);
tempCell = cell(N, 1);
for i =1:N
I = readimage(imds,i); % fixed from "N" to "i". Thanks to DGM's comment.
I = imrotate(I, 90);
I = im2gray(I);
tempCell{i} = I;
end
figure; montage(tempCell); title('processed image set')
1 件のコメント
DGM
2024 年 9 月 20 日
imds = imageDatastore(fullfile(matlabroot,"toolbox","images","imdata","AT3*.tif"));
N = length(imds.Files);
tempCell = cell(N, 1);
for k = 1:N
I = readimage(imds,k); % loop index!
I = imrotate(I, 90);
I = im2gray(I);
tempCell{i} = I;
end
% create an image
outpict = imtile(tempCell);
% save the image
imwrite(outpict,'myfile.png')
... but it seems more that the images should be saved individually within the loop, so the use of montage() may be strictly for visualization.
imds = imageDatastore(fullfile(matlabroot,"toolbox","images","imdata","AT3*.tif"));
outputpath = '.'; % pick where they go
N = length(imds.Files);
for k = 1:N
I = readimage(imds,k); % loop index!
I = imrotate(I, 90);
I = im2gray(I);
% if the visualization is not needed,
% the images can just be saved in the loop
[~,fname,ext] = fileparts(imds.Files{k});
thisfname = fullfile(outputpath,[fname ext]);
imwrite(I,thisfname)
end
... I'm assuming we're not overwriting the original files.
参考
カテゴリ
Help Center および File Exchange で Image Data Workflows についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!