I have a code that fetches the files about images from a folder. However, if I put two files it only returns 1 and not both. If I want to go to a directory and have two subfolders and want to get files from one folder and the other folder how can I do it?
clc;
close all;
clear;
workspace;
fontSize = 10;
imagePath = uigetdir('c:\');
imageFiles = [dir(fullfile(imagePath,'*.jpeg')); dir(fullfile(imagePath,'*.TIF')); dir(fullfile(imagePath,'*.PNG'))];
files = size({imageFiles.name},2);
filename = {imageFiles.name};
for i=1:files
f = fullfile(imagePath,char(filename(i)));
image= imread(f);
imshow(image)
FT=fft2(image);
magnitude=abs(fftshift(FT));
end

6 件のコメント

Monica Roberts
Monica Roberts 2022 年 7 月 13 日
This works well for me for multiple images. Is it possible that your images have different extensions other than "jpeg", "tif" or "png"? For instance, this doesn't capture "jpg" images.
PEDRO ALEXANDRE Fernandes
PEDRO ALEXANDRE Fernandes 2022 年 7 月 13 日
The problem is that if I want to do the FFT it only does it from one image and not from several images..
two images should appear and not just one
Geoff Hayes
Geoff Hayes 2022 年 7 月 14 日
@PEDRO ALEXANDRE Ferna - I'm not sure I understand. Isn't your above screen shot just showing the value for f which is a variable within your loop? Have you confirmed that imageFiles has only one file?
Stephen23
Stephen23 2022 年 7 月 14 日
編集済み: Stephen23 2022 年 7 月 18 日
"two images should appear and not just one"
You made no attempt to tile the images or save them or something similar, so on every iteration you simply discard the previous image so in the end you will only see the final image.
You also make no attempt to store FT nor magnitude, so these will also be overwritten on every loop iteration except the last one.
P = uigetdir('c:\');
S = [... much clearer than squeezing everything onto one line:
dir(fullfile(P,'*.jpeg'));...
dir(fullfile(P,'*.TIF'));...
dir(fullfile(P,'*.PNG'))];
for k = 1:numel(S); % better to use NUMEL()
F = fullfile(P,S(k).name);
I = imread(F);
imshow(I) % discarted except the last one
FT = fft2(I) % discarded except the last one
magnitude = abs(fftshift(FT)) % discarded except the last one
end
PEDRO ALEXANDRE Fernandes
PEDRO ALEXANDRE Fernandes 2022 年 7 月 18 日
Good afternoon.
Stephen23 you are right. The problem is that I am not seeing a way to solve the problem..
Stephen23
Stephen23 2022 年 7 月 18 日
"The problem is that I am not seeing a way to solve the problem.."

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

コメント済み:

2022 年 7 月 18 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by