Fourier transform for image data set

3 ビュー (過去 30 日間)
Mohamed Ahmed
Mohamed Ahmed 2020 年 11 月 17 日
コメント済み: Mohamed Ahmed 2020 年 11 月 17 日
Hello everyone
I'm writing a code for image dataset that has 1 main folder and 10 subfolders within, and I want to apply fourier transform to all images in these folders,
I wrote this code below but I can't find a way to access all 10 subfolders, and convert the images using (for loop).
This code gives me an error (MAP must be a m x 3 array) in (I = rgb2gray(I);) because of the size of (I).
can you please help me with this ?
code:
clc;
clear all;
img = dir('C:\AppliedProj\Train\0\*.jpg');
Images_num = length(img);
for i = 1:Images_num
fname = strcat('C:\AppliedProj\Train\0\', img(i).name);
I = imread(fname);
I = rgb2gray(I);
%Get Fourier Transform of an image
F = fft2(I);
% Fourier transform of an image
S = abs(F);
%get the centered spectrum
Fsh = fftshift(F);
%apply log transform
S2 = log(1+abs(Fsh));
%reconstruct the Image
F = ifftshift(Fsh);
f = ifft2(F);
path = strcat('C:\AppliedProj\New\0\', img(i).name);
imwrite(f,path);
end
Best regars

回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 11 月 17 日
編集済み: KALYAN ACHARJYA 2020 年 11 月 17 日
"This code gives me an error (MAP must be a m x 3 array) in (I = rgb2gray(I);) because of the size of (I)."
May be you are using Gray Scale Images, if yes then remove the rgb2gray assignmnet line and rest code will be same.
  2 件のコメント
Mohamed Ahmed
Mohamed Ahmed 2020 年 11 月 17 日
Yes, I need to convert it first to gray scale then apply the fourier transform,
I tried it with the (rgb2gray) function it worked but the resulting image was distorted
Mohamed Ahmed
Mohamed Ahmed 2020 年 11 月 17 日
*without

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

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by